I don't know why you would want to treat the bin
directories specially, I am guessing that you just want to see each directory on its own line. If so, you can just do:
printf '%s\n' "$PATH" | tr : '\n'
On my system, for example, where I have many directories in my $PATH
whose name doesn't contain bin
, that gives:
$ printf '%s\n' "$PATH" | tr : '\n'
/home/terdon/perl5/bin
/home/terdon/Setups/cd-hit-v4.5.4-2011-03-07
/sbin
/usr/local/sbin
/usr/bin
/usr/sbin
/home/terdon/Setups/PfamScan
/home/terdon/research/data/python
/home/terdon/scripts
/home/terdon/bin
If you really only want to see the bin
directories, you can extract them:
$ printf '%s\n' "$PATH" | tr : '\n' | grep '/bin$'
/home/terdon/saphetor/bin
/home/terdon/perl5/bin
/usr/bin
/home/terdon/bin
Or, if you want to do what you show in your answer and also include any directory that hjas the string bin
anywhere in its name, and not only those that are actually named bin
, you can do:
$ printf '%s\n' "$PATH" | tr : '\n' | grep 'bin'
/home/terdon/saphetor/bin
/home/terdon/perl5/bin
/sbin
/usr/local/sbin
/usr/bin
/usr/sbin
/home/terdon/bin
printf
instead ofecho $PATH | tr : "\n"
? – João Pimentel Ferreira Dec 09 '21 at 21:58