4 Ways of Executing a Shell Script in UNIX / Linux

Using File Name
Relative path

$ cd /home/anthony/
$ ./test.sh

or full path

$ /home/anthony/test.sh

Specifying the Interpreter
$ sh test.sh
$ bash test.sh

.  ./ (dot space dot slash)
While executing the shell script using “dot space dot slash”, as shown below, it will execute the script in the current shell without forking a sub shell.

$ . ./test.sh

Typically we use this method, anytime we change something in the .bashrc or .bash_profile. i.e After changing the .bashrc or .bash_profile we can either logout and login for the changes to take place (or) use “dot space dot slash” to execute .bashrc or .bash_profile for the changes to take effect without logout and login.

$ cd ~
$ . ./.bashrc

'Source' Command
You can achieve the same result for . ./ above with `source` command as below

$ source /home/anthony/.bashrc

No comments: