Home > Shell Scripting, UNIX > Calling a shell script from another shell script in the same directory

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


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
  1. No comments yet.
  1. No trackbacks yet.

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

%d bloggers like this: