Fun (?) with SH.  (Surprising behaviour...)
    idallen at watmath.UUCP 
    idallen at watmath.UUCP
       
    Sat Mar 24 07:55:48 AEST 1984
    
    
  
What does this line in a Bourne Shell command file print, when called
with the command arguments "1 2 3 4"?
   sh -c "/bin/echo And $@ were my arguments."
Answer:
   And 1
Why?  Because of the way "$@" expands, the command line becomes:
   sh -c "/bin/echo And 1" "2" "3" "4 were my arguments."
The invoked shell silently ignores the "2" and all following arguments,
and it executes "/bin/echo And 1".  I suppose this variation on the
expansion of "$@" makes sense (?!), but what reason is there to silently
ignore the following arguments?  (p.s. To fix the problem, change @ to *.)
-- 
        -IAN!  (Ian! D. Allen)      University of Waterloo
    
    
More information about the Comp.unix
mailing list