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

H

How Can We Help?

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

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

About the author

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.

About Author

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.

Follow Me