Skip to content

Instantly share code, notes, and snippets.

@josephwecker
Created June 6, 2012 19:55
Show Gist options
  • Select an option

  • Save josephwecker/2884332 to your computer and use it in GitHub Desktop.

Select an option

Save josephwecker/2884332 to your computer and use it in GitHub Desktop.

Revisions

  1. josephwecker created this gist Jun 6, 2012.
    10 changes: 10 additions & 0 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    #!/bin/bash
    # Put's the script's directory in the $BS variable.
    # Follows symlinks, works on mac-os as well as linux etc.
    # Move final popd to the end of your script if you want to run your script with the script's directory as the working directory.

    BS="${BASH_SOURCE[0]}";RL="readlink";([[ `uname -s`=='Darwin' ]] || RL="$RL -f")
    while([ -h "${BS}" ]) do BS=`$RL "${BS}"`; done
    N="/dev/null";pushd .>$N;cd `dirname ${BS}`>$N;BS=`pwd`;popd>$N

    # ... rest of the script ... use ${BS} when referring to this script's directory