Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rduplain
Created August 26, 2011 14:51
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 rduplain/1173578 to your computer and use it in GitHub Desktop.
Save rduplain/1173578 to your computer and use it in GitHub Desktop.
Answering: how can I reference the scripts directory and the working directory in GNU bash?
#!/bin/bash
# `dirname` is part of GNU coreutils, but is okay to use since it's in the Unix standard.
DIRNAME=`dirname $0`
echo script is at $DIRNAME
# Alternative, use pure bash substitution.
DIRNAME=${0%/*}
echo script is at $DIRNAME
# bash sets the current working directory in PWD
echo you are at $PWD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment