Xref: utzoo comp.unix.questions:7409 comp.unix.wizards:9105 Path: utzoo!utgpu!water!watmath!clyde!bellcore!rutgers!gatech!ncar!oddjob!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.unix.questions,comp.unix.wizards Subject: Re: Command line argument in Cshell script Keywords: command line argument, Cshell, string, spaces Message-ID: <11820@mimsy.UUCP> Date: 5 Jun 88 21:28:43 GMT References: <497@slb-sdr.UUCP> <534@unh.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 48 >In article <497@slb-sdr.UUCP> saito@slb-sdr.UUCP (Naoki Saito) writes: [much deleted] >>plot3d z=$TEMP -P $argv[2-] | sunplot In article <534@unh.UUCP> jeff@unh.UUCP (Jeffrey E. F. Friedl) writes: >Put quotes such as: >original: plot3d z=$TEMP -P $argv[2-] | sunplot >working: plot3d z=$TEMP -P "$argv[2-]" | sunplot > >Thus, when $argv[2] is expanded, it is expanded within quotes and is considered >one arg to plot3d. But `$argv[2-]' means `arguments 2 through $#argv'; quoting this will give a single word rather than multiple words, if $#argv > 2. If this is not wanted (as it apparently is not), use the :q modifier: plot3d z=$TEMP -P $argv[2-]:q | sunplot >... most shell scripts should be written in [k]?sh............ Seconded. Here is the original script: set TEMP=/tmp/z if (-e $TEMP) \rm $TEMP chkf -b -d $argv[1] > $TEMP plot3d z=$TEMP -P $argv[2-] | sunplot if (-e $TEMP) \rm $TEMP exit Here is how I might write it: case $# in 0) echo "usage: $0 file [arguments to plot3d]" 1>&2; exit 1;; esac TEMP=/tmp/z$$ # make a unique temporary file name /bin/rm -f $TEMP # remove it if it exists trap '/bin/rm -f $TEMP; exit' 0 1 2 3 15 # and again at exit or signal file="$1"; shift # pick up file name chkf -b -d "$file" > $TEMP # run chkf plot3d z=$TEMP -P ${1+"$@"} # plot, with optional arguments -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris