# Sorting a loop in bash and other possibilites
Author: tip
Date: 2008-04-04 00:00:00
Tags: bash, linux, tips
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?
EOF