Is there a way to change the command line arguments in a Bash script? For example, a Bash script is invoked like this:
./foo arg1 arg2
Is t
I know this is an old one but I found the answer by thkala very helpful, so I have used the idea and expanded on it slightly to enable me to add defaults for any argument which has not been defined - for example:
# set defaults for the passed arguments (if any) if not defined.
#
arg1=${1:-"default-for-arg-1"}
arg2=${2:-"default-for-arg-2"}
set -- "${arg1}" "${arg2}"
unset arg1 arg2
I hope this is of use to someone else.