Bash Shell Scripting

How to loop through the output of a Linux command in Bash

Written by Ian Carnaghan · 6 sec read >
for fileName in $(ls)
do
	echo $fileName
done

or a one liner

for fileName in $(ls); do echo $fileName; done

Replace the ls command with any Linux command

Last Updated On April 07, 2018
Written by Ian Carnaghan
I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment. Profile

Leave a Reply

avatar
  Subscribe  
Notify of