Skip to content

Instantly share code, notes, and snippets.

@brcontainer
Created August 1, 2016 23:46
Show Gist options
  • Save brcontainer/219c0de883ff8c57c3dcdf6572aedb01 to your computer and use it in GitHub Desktop.
Save brcontainer/219c0de883ff8c57c3dcdf6572aedb01 to your computer and use it in GitHub Desktop.
Obtain the path of the script and the way in which he was called (has not been tested yet, it is just to study)
#!/usr/bin/env bash
SCRIPT_PATH=$(realpath "$0")
CALLING_FROM=$(pwd)
if [ -d "$CALLING_FROM" ]; then
CALLING_DIR=$CALLING_FROM
else
CALLING_DIR=$(dirname "$CALLING_FROM")
fi
DIR_PATH=$(dirname $SCRIPT_PATH)
echo "-----------------------------------------------"
echo "\$0: $0"
echo "Real script path: $SCRIPT_PATH"
echo "Real dir path: $DIR_PATH"
echo "Calling from: $CALLING_FROM"
echo "Calling from dir: $CALLING_DIR"
echo "-----------------------------------------------"
read -rsp $'Press any key to continue...\n' -n 1 key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment