Skip to content
Discussion options

You must be logged in to vote

@brainwo You didn't necessarily need to write a separate script. you can somewhat easily solve this in your current script, like this:

func_a(){
	...
}

func_b(){
    ...
}

main(){
    ...
}
# Check if the script is being executed directly or if it's being sourced

if [ "$0" = "$BASH_SOURCE" ]; then

    # this code is called if you're running the script directly from the shell.
    # ie. from the shell doing a './myscript.sh'
    main "$@"

else

    # This code will run when the script is sourced. with a 'source myscript.sh'
   echo "thank you for sourcing my script. enjoy."
fi

Hopefully that's helpful. Sorry, didn't see this until just now. The above is at least what I do and has wo…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@brainwo
Comment options

Comment options

You must be logged in to vote
1 reply
@brainwo
Comment options

Answer selected by brainwo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants