KOOLz KOOLz - 18 days ago 6
Linux Question

How to list $PATH?

When I

echo $PATH

I get:
home/x/bin:home/x/.local/bin:...:...
and on and on where each path is separated by
:


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

I get:

home/x/bin
home/x/.local/bin
...
...


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:

#!/bin/bash
echo $PATH > 11
sleep 1
bb=${`tr ':' '\n' < 11`}
echo $bb


What can I do?

Answer

Use bash's Parameter Expansion:

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

Comments