Making a script executable

Longman, Bill longman at sharplabs.com
Wed Oct 6 10:22:01 MDT 2004


> I've put the following into a file called mg.
> 
> mount /dev/hdc7 /mnt/macosx -thfsplus
> 
> I have chmod a+x mg

Good.
 
> This is what the permissions look like for mg:
> 
> -rwxr-xr-x    1 edunbar edunbar       38 Oct  4 20:20 mg

Good.
 
> When I try to run it from the command line (bash) I get:
> 
> bash: mg: command not found

Bash is only smart enough to look in its PATH:

  echo $PATH

and you'll see where bash will look for programs to run. If the directory
that mg is in ain't on the PATH list, you'll have to point to it directly:

  /home/eric/bin/mg

or relatively:

  bin/mg

Those examples assume you've made a directory named bin in your directory
and placed it in there. It also assumes, in the second example, that your
current directory is /home/eric.
 
> 2nd question: I probably have to be root to mount a hfs+ 
> partition... how 
> can I build that into the script?

Your script can say this:

  sudo mount /dev/hdc7 /mnt/macosx -thfsplus

but there's a much easier way.


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.

My question to you: Why don't you just put the entry in the fstab file and
mount it automatically? If you want to do that, just replace the above
"user,noauto" with "defaults" and you'll be set.

Bill


More information about the yellowdog-general mailing list