Skip to content

Instantly share code, notes, and snippets.

@nickistre
Last active November 28, 2022 22:14
Show Gist options
  • Save nickistre/a2591a358f755ef101d870be125e591b to your computer and use it in GitHub Desktop.
Save nickistre/a2591a358f755ef101d870be125e591b to your computer and use it in GitHub Desktop.
Helpfull BASH script stuff
# From: https://stackoverflow.com/a/246128
# Basic script path information
SOURCE=${BASH_SOURCE[0]}
while [ -L "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
K1_BIN_DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )
SOURCE=$(readlink "$SOURCE")
[[ $SOURCE != /* ]] && SOURCE=$K1_BIN_DIR/$SOURCE # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
SOURCE_PATH=$(dirname $SOURCE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment