With Perl for UNIX / UNIX-like:
echo $PATH | perl -F: -ane '{print join "\n", @F}'
With any operating systems (tested on Windows XP, Linux, Minix, Solaris):
my $sep; my $path; if ($^O =~ /^MS/) { $sep = ";"; $path = "Path"; } else { $sep = ":"; $path = "PATH"; } print join "\n", split $sep, $ENV{$path} . "\n";
If you are using bash for Unix, try the following code:
printf '%s\n' ${PATH//:/ }
This is the use of the bash parameter extension
Gilles quenot
source share