Shell Scripting: Saving Shell scripts

For example, if we have shell script named “myshellscript.sh” (with execute permission) we can make it run in the current working directory with the commands

$ sh myshellscript.sh (or)
$ ./myshellscript.sh

If the shell scripts are stored in an executable path, it will save us from typing extra keystrokes. To find the paths that are setup, type

$ echo $PATH
/usr/bin: /usr/local/bin


In order to achieve the desired results, You can
i) save the shell scripts under /usr/local/bin as that path is already listed in the system path
ii) create a folder and add the path to the system path variable

Create a directory “scripts” under /usr/local
$ mkdir/usr/local/scripts

Move the script “myshellscript.sh” to /usr/local/scripts

$ export PATH=$PATH:/usr/local/scripts

Now, type
$ myshellscript.sh
and the shell script will execute as expected.

To set the path permanently, you have to edit .bashrc file.

Share

Written by kurinchilamp


Website: http://

Leave a Reply

Your email address will not be published. Required fields are marked *