sh(1) question from a "quoting paranoiac" :-)

Jerry Peek jdpeek at rodan.acs.syr.edu
Thu Mar 8 21:42:36 AEST 1990


I'm using these lines in a BSD-type Bourne shell script.  They give me
the last command line argument in $last and the others in $first:

    last="`expr \"$*\" : '.* \(.*\)'`"   # LAST ARGUMENT
    first="`expr \"$*\" : '\(.*\) .*'`"  # ALL BUT LAST ARG

Seems like, years ago, I needed to put doublequotes around the backquotes
to protect any spaces from the shell.  So, I write quoting nightmares like
that one.  But maybe I've got over-quoting paranoia. :-)  Would this be safe?

    last=`expr "$*" : '.* \(.*\)'`   # LAST ARGUMENT
    first=`expr "$*" : '\(.*\) .*'`  # ALL BUT LAST ARG

Our BSD-type sh(1) man page seems to say that it's okay (?):

    After parameter and command  substitution,  any  results  of
    substitution  are scanned for internal field separator char-
    acters (those found in $IFS) and split into  distinct  argu-
    ments  where such characters are found...

I'd like this script to be portable.  Is there any Bourne shell
(including mine!) that will choke on the less-quoted version?  Thanks.

--Jerry Peek; Syracuse University Academic Computing Services; Syracuse, NY
  jdpeek at rodan.acs.syr.edu, JDPEEK at SUNRISE.BITNET        +1 315 443-3995



More information about the Comp.unix.questions mailing list