The usual code to check the $PATH variable echo $PATH
often print out some long and cumbersome line like:
/anaconda2/bin:/anaconda2/condabin:/usr/local/Cellar/root/6.16.00/bin:~/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin
which has bad readability. Is there any way I can print all the paths line by line instead on a single line? Like this:
/anaconda2/bin
/anaconda2/condabin
/usr/local/Cellar/root/6.16.00/bin
~/bin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/Library/TeX/texbin
/opt/X11/bin
Using tr
:
echo $PATH | tr : '\n'
Try this code:
echo $PATH | sed 's|:|\
|g'
sed is a stream editor, and what it does here is searching for every instance of character ':' and replace it with a \newline character. 'g' is a flag indicating that the find & replace is global (the default is to replace one instance per line).
You can also wrap the code around a function in bash profile:
function printpath() {
echo $PATH | sed 's|:|\
|g'
}
so you can just type printpath
to get the desired output.
echo -e ${PATH//:/\\n}
use variable substitution to replace the colon with a newline
${var//Pattern/Replacement}
-e enable interpretation of backslash escapes
If -e is in effect, the following sequences are recognized:
\\ backslash
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With