KOOLz KOOLz - 1 year ago 79
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?

Answer Source

Use bash's Parameter Expansion:

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download