You could make use of the set
builtin in order to change a positional parameter.
The following snippet changes the first positional parameter, i.e. $1
, to something
:
set -- "something" "${@:2}"
As an example, refer to the following:
echo "Original parameters: $@"
set -- "something" "${@:2}"
echo "Modified parameters: $@"
Assuming this was placed in a script called script
, and was invoked by saying bash script foo bar baz
, it'd output:
Original parameters: foo bar baz
Modified parameters: something bar baz
Quoting from help set
:
set: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
Set or unset values of shell options and positional parameters.