Skip to content

Instantly share code, notes, and snippets.

@josephwecker
Created December 23, 2013 22:23
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 josephwecker/8105846 to your computer and use it in GitHub Desktop.
Save josephwecker/8105846 to your computer and use it in GitHub Desktop.
Slightly more robust "current directory" for bash script if ruby is already a dependency
#!/bin/bash
D=`ruby -e 'puts File.dirname(File.realpath(File.expand_path("'${BASH_SOURCE[0]}'")))'`
pushd "${D}" >/dev/null
# ... Do stuff ...
popd >/dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment