Man-Ching’s ksh scripts
Interesting scripts, but I have another solution to the splitting problem using IFS.
I offer the following, which should work in vanilla bourne shell, with the using the same delimeters as Man-Ching used.
pl.sh#!/bin/sh line="$@" # Save the argument list IFS="|" # Make '|' the field seperator set -- $line # reset the argument list for column # loop through $* do echo $column done
Giving the same result
./pl.sh `head -1 /etc/passwd | sed 's/:/|/g'` root x 01 Super-User / /sbin/sh
Indeed you could do the whole part in grave accents in a single sed command.
./pl.sh `sed -e 's/:/|/g' -e 1q /etc/passwd` root x 01 Super-User / /sbin/sh
Which actually goes to demonstrate a bit of unix philosopy. That is, there are many ways to achieve the same end; none is necesarily the best, or more simply, there is more than one right way to do anything.