I would like to understand what the following command does
set -- "$@" "-h"
The gnu manual says
--
If no arguments follow this option, then the positional parameters are unset.
Otherwise, the positional parameters are set to the arguments, even if some
of them begin with a ‘-’.
I cannot take much useful information from such description though.
As I understand it, the following appends -h
to the function argument list.
set -- "$@" "-h"
But, how is it that the following actually replaces --help
with -h
, etc.
printf '%s\n' "$*"
for arg in "$@"; do
shift
printf '%s\n' "--> arg: $arg"
case "$arg" in
"--Version") set -- "$@" "-V" ;;
"--usage") set -- "$@" "-u" ;;
"--help") set -- "$@" "-h" ;;
"--verbosity") set -- "$@" "-v" ;;
*) set -- "$@" "$arg" ;;
esac
done