Created
June 22, 2023 17:54
-
-
Save cowlicks/9fa3d8936d3d926ce8e55fdba23322a5 to your computer and use it in GitHub Desktop.
Location agnostic bash script. Demonstrate using paths relative to script, and working directory. Return to working directory on script end.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# exit on first failure | |
set -e | |
# uncomment to enable debug mode | |
#set -x | |
# The location this script is run from | |
OG_DIR=$(pwd) | |
# The directory that this script is in | |
SCRIPT_DIR=$(dirname -- "$0"); | |
# Return to orignal director the script was run from | |
trap "cd $OG_DIR" EXIT | |
# Go somewhere or do something relative script location. The `trap` will put us back later | |
pushd "$SCRIPT_DIR/.." | |
echo "HELLO THESE ARE THE ARGS $@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment