Determining own directory path in unix bash script

In a unix bash script, you can determine the scripts filesystem location by using

SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"

This is especially useful if you want to use “relative” (well, sort of) paths within your script, regardless of which directory the script is being executed from, e.g.

java -jar $SCRIPT_DIR/libs/some-file.jar

If you just used libs/some-file.jar the bash script would only work when executed from the directory it is located in.


Tags: , , , ,

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: