Last active
June 7, 2023 12:07
-
-
Save hnakamur/542d7e49ffb8e0322d7cd4492ee0f7e3 to your computer and use it in GitHub Desktop.
Find out whether a bash script is executed or sourced.
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
#!/bin/bash | |
if [ $BASH_ARGV0 = -bash ]; then | |
echo sourced | |
else | |
echo executed | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
${FUNCNAME[-1]}
to get the last element in an array: https://unix.stackexchange.com/a/198789/135274