Sunday, January 17, 2010

Include a shell file into another one

It is a easy task indeed. Suppose, we have two shell script file in same directory. These are firstShell.sh and secondShell.sh. To include the first script in the second, we just need to write the following statement in the second shell script -

source firstShell.sh

If the fistShell.sh is not in same directory then we need to refer the script with full path -

source /path/firstShell.sh

One more thing is if the included shell script requires some arguments to execute, you can pass the arguments where you refer the script. So if the first shell requires some arguments, you have to write -

source /path/firstShell.sh arg1 arg2 ...

No comments: