Advertisement
TangentFox

Bash: Find script's directory

Jan 27th, 2021
1,183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.43 KB | None | 0 0
  1. SOURCE="${BASH_SOURCE[0]}"
  2. while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
  3.   DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null && pwd )"
  4.  SOURCE="$(readlink "$SOURCE")"
  5.  [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
  6. done
  7. DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null && pwd )"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement