Skip to content

Instantly share code, notes, and snippets.

@nicerobot
Created December 29, 2011 21:20
Show Gist options
  • Save nicerobot/1536253 to your computer and use it in GitHub Desktop.
Save nicerobot/1536253 to your computer and use it in GitHub Desktop.
Is a bash script sourced or executed directly?
sourced() { [ 'bash' == "${0:-i}" ] || [ "${BASH_SOURCE[0]}" != "${0:-i}" ]; }
# Example:
# sourced && return 0 || exit 0
# For some reason, this function needs to be defined in the same context in which it's used.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment