Created
May 8, 2013 09:02
-
-
Save physacco/5539224 to your computer and use it in GitHub Desktop.
A utility function for getting the directory of the shell script itself.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
script_dir() | |
{ | |
local SCRIPT_PATH=${BASH_SOURCE[0]} | |
while [ -L "${SCRIPT_PATH}" ]; do | |
SCRIPT_PATH=`readlink "$SCRIPT_PATH"` | |
done | |
local SCRIPT_DIR=`dirname "${SCRIPT_PATH}"` | |
pushd . > /dev/null | |
cd "$SCRIPT_DIR" > /dev/null | |
SCRIPT_DIR=`pwd` | |
popd > /dev/null | |
echo "$SCRIPT_DIR" | |
} | |
ScriptDir=`script_dir` | |
echo $ScriptDir |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment