View Full Version : Mount


barghota
Salamo 3alekom,

if we created a shell program using a text editor, suppose that the shell program is for mounting and umounting the cd-rom

in the text editor the text will be:

umount /mnt/cdrom
mount /mnt/cdrom /cdrom

i hope i am right

if i want to make this program executable how do i make it?
and if i want to run the program just by commands from a console how could i make it?

thnx alot.

alaa
>mount /mnt/cdrom /cdrom

first of all, what exactly are you trying to achieve with that line??

to make a script executable you need to change its permissions using chmod

chmod +x foo

where foo is the th script's filename

if you want this script to be executable by all users you should use

chmod 0755 foo

you really need to learn about Unix permissions and the chmod command, check the chmod man page and tell us if you need further explanations.

cheers,
Alaa

MadFarmAnimalz
Thee's the hash-bang hack thingie too.

#!/bin/interpreter

sattia
First u ve to man chmod.
chmod +x; as told by alaa; sets the e(X)ecute permission to all; owner, group, and world
but it leaves u uncertain about the final state of attributes.
For example if the original attrs r ??-??-??- then after chmod +x the permissions will be ??x??x??x
The ?? here denote the uncertainty of the final permission. I mean that chmod +x just adds x to the permissions without affecting the originals or even bothering what they are.
While chmod 0755 sets the final permissions to rwxr-xr-x. They r equal in the effect that x is added to all.

Regarding ur 2nd question.
The env variable PATH is used to do this.
When u type a command on the shell it fetches the directories in the PATH (echo $PATH) for this file. If found it runs it otherwise an error message appears. Unlike Windows it does not into the current directory by default unless it is explicitly type using the './' notation.
The dot stands for the current directory while the slash separates the path components.
So if a script foo is in ur PATH then u would simply type
$ foo
if it is not then u ve to give the shell the path to foo
$ /path/to/foo
if foo is in ur current direcotry then the /path/to/foo would be
$ ./foo
if it is in /usr/local then the /path/to/foo will be
$ /usr/local/foo
provided that the foo script has an x permission for the user attempting ro tun it.
If it dsnt ve an x permission then for the examples above just tell the shell to handle it by preceding the commands above with sh so becomes:
$ sh /path/to/foo