I'm executing a shell script and passing few command line arguments to it.
I want to modify the arguments inside the script using set
. Not all at once depending upon some conditions.
How can I do that?
I'm executing a shell script and passing few command line arguments to it.
I want to modify the arguments inside the script using set
. Not all at once depending upon some conditions.
How can I do that?
Copy unmodified arguments at their respective location within set --
Say you want to modify value of argument 2:
set -- "${@::2}" 'new arg2 value' "${@:3}"
Explanation:
"${@::2}"
: Expands 2 arguments from index 0 (arguments 0 and 1)new arg2 value
: Becomes the value for argument 2."${@:3}"
: Expands all argument values starting at index 3.Opinion:
Anyway, having mutable arguments is considered code-smell in modern programming. So I'd recommend you reconsider your approach to the problem you are trying to solve.