Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!mcvax!hp4nl!botter!star.cs.vu.nl!maart From: maart@cs.vu.nl (Maarten Litmaath) Newsgroups: comp.unix.questions Subject: sh vs. csh format script (was: Re: Vi) Message-ID: <2760@piraat.cs.vu.nl> Date: 14 Jun 89 21:15:58 GMT References: <297@ontek.UUCP> Organization: V.U. Informatica, Amsterdam, the Netherlands Lines: 61 mikey@ontek.UUCP (Mike Lee) writes: \... \# csh script to call up nroff on a paragraph \# \set temp_file = /tmp/foom.$$ \ \# change default indentation to your liking \set columns = 2 \if ( $1 != "" ) set columns = $1 \ \echo ".hy 0" >! $temp_file \echo ".pl 1" >> $temp_file \ \cat | shift_lines -$columns >> $temp_file \nroff $temp_file | shift_lines $columns \ \rm $temp_file \... 1) You shouldn't use csh for scripts: - sh starts up faster - sh often is more powerful (csh has built-in arithmetic, arrays, modifiers like `:t', comma-separated lists) - sh often is easier/clearer From the csh manual: Quoting conventions are contradictory and confusing. The only way to direct the standard output and standard error separately is by invoking a subshell, as follows: tutorial% (command > outfile) >& errorfile Although robust enough for general use, adventures into the esoteric periphery of the C-Shell may reveal unexpected quirks. 2) `cat |' is almost a no-op: it slows things down Well, here's a Bourne shell script: #!/bin/sh # change default indentation to your liking columns=${1-2} temp_file=/tmp/foobar.$$ umask 077 exec 3>&1 > $temp_file 4< $temp_file /bin/rm $temp_file echo ".hy 0" echo ".pl 1" shift_lines -$columns nroff <&4 | shift_lines $columns >&3 -- "I HATE arbitrary limits, especially when |Maarten Litmaath @ VU Amsterdam: they're small." (Stephen Savitzky) |maart@cs.vu.nl, mcvax!botter!maart