KOOLz KOOLz - 7 months ago 44
Linux Question

How to list $PATH?

When I

echo $PATH

I get:
and on and on where each path is separated by

When I
echo $PATH | tr ':' '\n'

I get:


Where very path is separated by a new line

So now I want to fit all of this into a variable (
) or a script so I can execute it and it lists the path by line, but it wont work:

I tried:
x=${echo $PATH | tr ':' '\n'}

but I get
-bash: ${echo $PATH | tr ':' '\n'}: bad substitution

I also tried a script where:

echo $PATH > 11
sleep 1
bb=${`tr ':' '\n' < 11`}
echo $bb

What can I do?


Use bash's Parameter Expansion:

echo "${PATH//:/$'\n'}"