I played shell golf with myself today. (I won.)
I started with
echo $PATH | perl -F: -lane'$,="\n"; print @F'
and Ask intervened with
perl -e'print join"\n",split(/:/,$ENV{PATH}),""'
claiming it was "the same length and is using more common idioms.". I noted that his was a lot more typing and punctuation, and mine is mostly whitespace.
I shifted into Awk for a few cycles:
echo $PATH | awk 'BEGIN{RS=":"} {print}'
echo $PATH | awk -vRS=: '{print}'
but what I really wanted was sed. I settled with perl
echo $PATH | perl -pe's/:/\n/g'
after determining that tcsh was breaking sed.
But..
echo $PATH | tr : '\n'
I win.
My nick is oneiron, so I better take a swing at this. What is the shortest version that uses perl?
perl -le"s,,$PATH,,y,:,\n,,print"
echo $PATH|perl -pey,:,\\n,
( IFS=:; for x in $PATH; do print $x; done )
Re:Purely shell solution
Robrt on 2003-08-05T18:08:57
I like this one.Re:Purely shell solution
prakash on 2003-08-05T18:48:37
As long as we are golfing, why useecho
is there to save you one char?
( IFS=:; for x in $PATH; do echo $x; done )
/prakash