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.
./check_test_results.sh $publish_pcom_test $publish_svs_testThis is how I'm executing the script. The two arguments are having some default values(True/False). I want to do some operations and want to decide whether I have to modify these argument values or not. If I have to update these values then how can I do that?$1and$2Check this thread --> stackoverflow.com/questions/192249/…set$publish_pcom_test $publish_svs_testright ? tryexport $publish_pcom_test="Blah blah "