Making a script executable

Longman, Bill longman at sharplabs.com
Wed Oct 6 12:42:25 MDT 2004


> >I would have written it this way:
> >
> >   exec /bin/mount /mnt/macosx
> >
> >And then I would have made this entry in my /etc/fstab file:
> >
> >   /dev/hdc7   /mnt/macosx   hfsplus  user,noauto  0  0
> >
> >Then you can just run your mg script and it will mount for 
> you without root
> >permissions.
<snip>
> similar suggestions). I'll be reading up on exec to see what 
> it does (when I 

When you run a script, it's bash who's actually interpreting the shell
commands and running what you tell it to. The process tree looks like this
(when it's running "mount"):

  - your shell
   \- your mg script
     \- the mount command

When you use "exec", instead of forking a new process, the existing process
is overwritten by the new one. As such, that means it's the end of the line
for the commands in your script. The process tree would then look like this:

 - your shell
  \- the mount command

Since your script's sole function is to run the mount command, you may as
well get rid of the superfluous bash process, since all it's doing is
waiting for mount to exit. It does nothing else, so just run mount and save
some RAM.

Try this from your prompt:

  exec ls

and you'll get a directory listing and a logout.



More information about the yellowdog-general mailing list