While trying to make a script that provides a set of functions, I saw it convenient to define the following behavior depending on how the script was being invoked, whether by sourcing or by execution:
- When sourcing: Simply define the functions
- When executing: Run one of the functions (as a sort of "default") with arguments passed from
$@
The way I thought for discriminating among both ways was by leveraging $0
.
The main constraint was that this should work in a fully POSIX-compliant shell, or as close as possible otherwise.