Skip to content

Instantly share code, notes, and snippets.

@goddoe
Created December 17, 2021 17:29
Show Gist options
  • Select an option

  • Save goddoe/af5f4fc93fba09fb8c2163fbb7f5aef6 to your computer and use it in GitHub Desktop.

Select an option

Save goddoe/af5f4fc93fba09fb8c2163fbb7f5aef6 to your computer and use it in GitHub Desktop.
curr script dir
$ cat test.sh
#!/usr/bin/env bash
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
echo $SCRIPT_DIR;
$ ./exps/test.sh
/abs/path/to/exps
$ cd exps
$ ./test.sh
/abs/path/to/exps
$ cat test_2.sh
#!/usr/bin/env bash
SCRIPT_DIR=$(dirname $0)
echo $SCRIPT_DIR;
$ ./exps/test_2.sh
./exps
$ cd exps
$ ./test_2.sh
.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment