bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 1/2] utils: escape arguments in fakeroot.sh


From: Ivan Shmakov
Subject: Re: [PATCH 1/2] utils: escape arguments in fakeroot.sh
Date: Sun, 25 Aug 2013 16:57:26 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux)

>>>>> Justus Winter <address@hidden> writes:
>>>>> Quoting Ivan Shmakov (2013-08-25 17:55:39)

[…]

 >>      /bin/fakeauth /bin/sh \
 >>          -c 'cd "$1" || exit ; shift ; exec "$@"' \
 >>              dummy.sh "$(pwd)" "$@" \

 > ?

        The essential point is that using -c doesn’t prevent one from
        passing command line arguments (and the value for $0) to the
        script, thus the following two forms are both perfectly valid:

$ sh -c 'printf :%s\\n "$@"' \
      my.sh foo bar 
$ sh  my.sh foo bar 

        The only difference is that the first command doesn’t actually
        /read/ my.sh.  (But it sets $0 to my.sh anyway.)

        Specifically, the code suggested sets the $0, $1, … values for
        the spawned (-c) shell code to “dummy.sh”, the current working
        directory, and this shell’s own positional arguments,
        respectively.  Then, ‘shift’ drops the directory (initially $1),
        and the remaining positional arguments ("$@") of the child would
        be a copy of that of the parent.

        … But probably the best part of it is that this behavior is
        specified by POSIX:

--cut: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sh.html --
  -c  Read commands from the command_string operand.  Set the value of
      special parameter 0 (see Special Parameters) from the value of the
      command_name operand and the positional parameters ($1, $2, and so
      on) in sequence from the remaining argument operands.  […]
--cut: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sh.html --

[…]

-- 
FSF associate member #7257      http://sf-day.org/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]