Archive

Archive for the ‘Shell Scripting’ Category

Calling a shell script from another shell script in the same directory

April 3, 2012 Leave a comment

Often when creating a shell script you need to invoke another shell script located in the same directory.

Since your script may be invoked from any place on the file-system, the reference to the other script must be absolute – not relative.

Here is how to do it:

...
SCRIPT_DIR=`dirname $0`
. ${SCRIPT_DIR}/other_script.ksh
...

The call to dirname $0 returns the path to the currently running script ($0). The path is relative to the present working directory (PWD).

Advertisements
Categories: Shell Scripting, UNIX
%d bloggers like this: