Fixing bash script bogosity - help?

pgf at laptop.org pgf at laptop.org
Tue Apr 28 10:33:42 EDT 2009


bert wrote:
 > 
 > On 28.04.2009, at 15:09, pgf at laptop.org wrote:
 > 
 > > bert wrote:
 > >>
 > >> On 28.04.2009, at 14:27, pgf at laptop.org wrote:
 > >>
 > >>> bert wrote:
 > >>>>
 ....
 > >>>>
 > >>>> Maybe you should use su directly instead of runuser?
 > >>>
 > >>> won't that have the same problem?  it still wants a command
 > >>> passed via a -c STRING convention.
 > >>>
 > >>> i think this is somewhat intractable, and any time spent on it
 > >>> would be better spent creating a patch to runuser that lets it
 > >>> take its command as strace does, or as xterm does with -e, which
 > >>> avoids the vector->string->vector translations which are the real
 > >>> issue.
 > >>
 > >>
 > >> No, su passes all arguments after -c to the program you specify.
 > >
 > > can you give an example?
 > >
 > >    $ su root -c /bin/echo one two three
 > >    Password:
 > >
 > >    $ su root -c '/bin/echo one two three'
 > >    Password:
 > >    one two three
 > >    $
 > 
 > 
 > It's not a problem in su but in bash. See "man bash":
 > 
 >   -c string If  the  -c  option  is  present, then commands are read  from
 >             string.  If there are arguments after the  string,  they   are
 >             assigned to the positional parameters, starting with $0.
 > 
 > Note it starts with $0 not $1. So this works:
 > 
 > $ su root -c '/bin/echo "$@"' /bin/echo one two three

thanks -- i'd never seen that done before.  (and it certainly
wasn't possible with the original shells.)  whenever someone
teaches me something like that, i always wonder how long ago i
missed the memo announcing the new feature.  :-)

martin:  switch from runuser to su, just like bert said.  :-)

paul
=---------------------
 paul fox, pgf at laptop.org



More information about the Devel mailing list