Skip to content

Instantly share code, notes, and snippets.

@xeor
Created October 29, 2015 08:39
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 xeor/111408770b20bc3a2d04 to your computer and use it in GitHub Desktop.
Save xeor/111408770b20bc3a2d04 to your computer and use it in GitHub Desktop.
Store the scripts folder in a variable
#!/bin/bash
# Finding out which script-folder your bash-script runs in can be problematic.
# Here is a quick solution that tries to be cross-platform and support every odd-cases. Like if your script is runned via a symlink.
mydir=$(cd $(dirname $(readlink -f "${BASH_SOURCE:-$0}"));pwd)
cd ${mydir}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment