marcus-g
5/8/2017 - 5:50 AM

How to include the functions and execution sequences of another shell file From http://stackoverflow.com/questions/12815774/importing-funct

How to include the functions and execution sequences of another shell file

From http://stackoverflow.com/questions/12815774/importing-functions-from-a-shell-script

#!/bin/sh

foo() {
    echo foo $1
}

main() {
    foo 1
    foo 2
}

if [ "${1}" != "--source-only" ]; then
    main "${@}"
fi


#----------------- Script sourcing above one ------------------
# sourcing-script.sh
#!/bin/sh

. ./script.sh --source-only
foo 3

### console
./sourcing-script.sh
foo 1
foo 2
foo 3