Skip to content

Instantly share code, notes, and snippets.

@physacco
Created May 8, 2013 09:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save physacco/5539224 to your computer and use it in GitHub Desktop.
Save physacco/5539224 to your computer and use it in GitHub Desktop.
A utility function for getting the directory of the shell script itself.
#!/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