Last active
September 22, 2022 18:15
-
-
Save rikvermeer/f8c80f7922840a2d405c9129a2456b23 to your computer and use it in GitHub Desktop.
bash file that can be sourced or executed. knows where to look for files
This file contains 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 | |
CURDIR=${PWD} | |
COMMAND="${BASH_SOURCE:-$0}" | |
TARGET=$(basename $COMMAND) | |
TARGET_DIR="$( cd "$(dirname $COMMAND)" ; pwd -P )" | |
function main() { | |
echo "Hello ${@}" | |
echo "Curdir = ${CURDIR}" | |
echo "Command = ${COMMAND}" | |
echo "Target dir (pwd) = ${TARGET_DIR}" | |
echo "Target = ${TARGET}" | |
} | |
# Execute function if file is not being sourced | |
[[ $0 != "$BASH_SOURCE" ]] || main $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Execute as bash script
Source script