Displaying usage comments in functions intended to be used interactively
I don't think that there is just one good way to do this.
Many functions, scripts, and other executables provide a help message if the user provides -h
or --help
as an option:
$ foo() {
[[ "$1" =~ (-h|--help) ]] && { cat <<EOF
Usage: foo [bar]
Foo's a bar into a baz
EOF
return;
}
: ...other stuff...
}
For example:
$ foo -h
Usage: foo [bar]
Foo's a bar into a baz
$ foo --help
Usage: foo [bar]
Foo's a bar into a baz