Reggie Kapros Reggie Kapros - 6 months ago 12
Bash Question

Manipulate the output of echo $PATH

With

echo $PATH
I get this:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games


And what I would like is to get these in the following format:

/usr/local/sbin
/usr/local/bin
...


What I tried to do:

i=1;
for dir in `echo $PATH|cut -d ':' -f $i`
do
echo $dir
i=`expr $i + 1`
done


But it doesn't work. Could someone help me with an answer?

Answer

tr to the rescue:

echo "$PATH" | tr : '\n'
Comments