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

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



>>>>> Justus Winter <4winter@informatik.uni-hamburg.de> 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 to: