All about programming in GNU/LINUX

Executing a shell script

(NOTE:Make sure the path where you have saved the file and your current working directory in the terminal are same )Let XYZ be the name of the shell script you have created .By executing the command , “/bin/sh XYZ” in the terminal the script can be executed .The script can be invoked like any other executable , to do it first the script has to be given a executable permission .Use “chmod +x XYZ” , to give executable permission . Then use “./XYZ”  on the terminal to invoke the script.If you want to invoke the script just by calling its name , just use this command “PATH=$PATH:” to set the shell environment variable to look into the current path too.Now just execute the script from the terminal by using its name , “XYZ”, and script works !!Specifying the path prepended with ./ does have one other advantage: It ensures that you don’t accidentally execute another command on the system with the same name as your script file.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s