Shell scripting basic doubt

Hi,
I have a script called sam.sh which consists of a single echo statement like this

#/usr/bin/ksh
echo "Mani"

I changed the mode for the script by giving chmod a+x sam.sh.

If I want to execute the scrpt by just giving the name at the command line "sam.sh", what should I necessarily do? I dont want to execute the script as ./sam.sh

Thanks in advance

ksh sam.sh

and for this you don't need to do chmod
or

sam.sh

Add sam.sh to one of the directories listed in your path settings.

echo $PATH will give the list fo directories

The solutions above will only work if the directory containing the script is in your path - the reason you have to type ./sam.sh is to specify the that the script is in your current working directory (.).

You could change your path to include the directory containing the script (your home directory?) or the current directory (.) or, better, create an alias, e.g.

alias sam.sh=<absolute directory path>/sam.sh

Note that this needs to be an absolute path starting with a slash (like /home/mine) not relative to the current working directory (like ./mine) so that it will work whichever directory is current.

Put this in your login file (.profile, .bash_profile, .cshrc or whatever it is for your system) to make it available each time you log in.

cheers