Trylinux.org
 

April 4, 2008

Sorting a loop in bash and other possibilites

Filed under: bash, linux, tips — tip @ 4:15 pm

As I said in my previous post, I learned a couple things about bash today. I had a nice for loop that outputted the info I wanted, but not in the right order. I thought to myself, man if this were php I would just put it in an array and sort it before looping across it. I bet this will be a pain in bash.

BUT, I was pleasantly surprised to find out how simple this really was. If you want to perform an action the output of a loop in bash then you just pipe done into the fuction you want performed. See the example below.

for VAR in $VARS; do
{someaction}
done | sort -n

Cool, right?

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment