Last active
February 21, 2023 21:03
-
-
Save AfroThundr3007730/6f3b146548b29a93b7097c10c02ae970 to your computer and use it in GitHub Desktop.
Making executable scripts source-friendly
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
# This file can be sourced and also executed directly | |
# Definitions and declarations go here | |
function main () { | |
# All action happens here | |
return 0 | |
} | |
# Only run if not sourced | |
if(!($MyInvocation.InvocationName -eq '.')) { | |
main $args | |
} |
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/python | |
# This file can be sourced and also executed directly | |
# Definitions and declarations go here | |
def main(): | |
# All action happens here | |
return 0 | |
# Only run if not sourced | |
if __name__ == '__main__': | |
main() |
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
#!/bin/bash | |
# This file can be sourced and also executed directly | |
# Definitions and declarations go here | |
main () { | |
# All action happens here | |
return 0 | |
} | |
# Only run if not sourced | |
if [[ ${BASH_SOURCE[0]} == "$0" ]]; then | |
main "$@" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment