Skip to content

Instantly share code, notes, and snippets.

@lambdalisue
Last active September 26, 2015 19:17
Show Gist options
  • Select an option

  • Save lambdalisue/1145772 to your computer and use it in GitHub Desktop.

Select an option

Save lambdalisue/1145772 to your computer and use it in GitHub Desktop.
Get absolute execution directory path in Sh
#!/bin/sh
# --- long way
ROOT=`dirname $0`
ROOT=`cd $ROOT;pwd`
# --- short way
ROOT=$(cd $(dirname $0);pwd)
# --- with readlink
SELF=$(readlink -f $0)
ROOT=$(dirname $SELF)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment