On Fri, 2004-08-06 at 17:57, [EMAIL PROTECTED] wrote:
> How come the following script deletes itself?
> 
> #!/bin/rm
 ^^^^^^^^^^^^
Standard #! behavior.  Your little file isn't a script at all because
you specified rm as the shell script processing command, which of course
rm is not.  Whenever the kernel sees an executable file with a #! as the
first line, it then takes the remaining part of that line as the command
to execute and feeds it as the first argument, followed by any arguments
you passed the script.

> # Self-deleting script.
> 
> # Nothing much seems to happen when you run this... except that the file
> disappears.
> 
> WHATEVER=65
> 
> echo "This line will never print (betcha!)."

Obviously.  rm is not a scripting language.  It knows nothing about bash
commands which you have placed in the commands.

> 
> exit $WHATEVER  # Doesn't matter. The script will not exit here.

Anything in this file is meaningless.

to recap:

#!/prog means that this script will be executed by prog by passing it as
a paramater. 

For example:

cat > test.sh
#!/bin/bash
echo $1

chmod a+rx test.sh
./test.sh Hello
   -->translates to-->
/bin/bash ./test.sh Hello

Michael



> 
> 
> 
> ____________________
> BYU Unix Users Group 
> http://uug.byu.edu/
> ___________________________________________________________________
> List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list
-- 
Michael L Torrie <[EMAIL PROTECTED]>


____________________
BYU Unix Users Group 
http://uug.byu.edu/ 
___________________________________________________________________
List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list

Reply via email to