Non-Gripes about /bin/sh

Larry Cipriani lvc at danews.UUCP
Tue Jun 10 06:17:00 AEST 1986


I think you'll find that the shell is far more powerful
than the manual page would lead one to believe.  I've been
using it for 4 years and I'm still learning things about it.
I don't know about csh, as I've never used it.

The sh manual page describes how to do what you described
with multiple files in the Input/Output section.  Here
are some examples to make it more concrete.

	exec 3>&1	# make file descriptor 3 a duplicate of stdout

	exec >${filen}	# stdout now goes to $filen

	exec 2>${filen}	# stderr now goes to $filen

	exec 0<${filen}	# connect stdin to $filen
	while read line
	do
		stuff
	done

Also, consider:

	lu="ls -l /usr/spool/uucppublic"

Then,

	$lu	# type in the $ too.

will execute ls -l /usr/spool/uucppublic.  Is this what you wanted ?

If you have to do some trick substitutions in a command, try
eval.  Here is a small shell script that uucp's a list of files
to a predetermined location ($HOME/lvc/uucp) on another machine.

case ${#} in
   0|1)	echo "usage: ${0} filen, ..., filen machine" >&2 ; exit 1 ;;
     *)	eval "case \${$#} in
	    cbsc[acefghklmn]|danews) uucp ${*}!~lvc/uucp ;;
	    * ) echo ${0}: \${$#} invalid machine >&2 ; exit 1 ;;
	esac" ;;
esac

Hope this answers some of your questions.  There are some undocumented
features in the the shell, but you'll have enough work ahead of you
learning the documented ones first.

If you can get U of W to buy the code for the Korn Shell (only
$2000 for the source) it's well worth the money.
-- 

Larry Cipriani		AT&T Network Systems
danews!lvc		"Nothing is worse than an itch you can never scratch."



More information about the Comp.unix mailing list