How could we execute a program with "dynamic arguments" (loop) ?
I would like to add an argument as per user interest/input. I can do it by several if conditions, But it is not practical. Arg1, Arg3, and Arg4 might be needed for a program (eg: docker run ) but Arg2 and Arg5 are not.
For example:
docker run -d --name $CONTAINER_NAME \
--hostname $MY_PROFILE \ ## if $hostname_req=1
--user $USER \
-v $MYAPP_DL:/home/$USER/Downloads \ ## if $dwnldfolder_req=1
--net-alias=${MY_NEW_DNS_NAME} \ ## if $dns_req=1
--label "appname=$MYAPP" \ ## if $label_req=1
--label "profile=$DOMAIN_CODE" \
--label "purpose=$PURPOSE" \
--label "maintainer=$DEV_ID" \
$DOCKER_IMAGE_TAG
We can use function and loop but how will substitute to Program ( docker run ) arguments?
## NOT ACTUAL CODE :: ILLUSTRATING PLAN1
if [$label_req==1]
argument_aray+=('--label "appname=$MYAPP"')
if [$dns_req==1]
argument_aray+=('-net-alias=${MY_NEW_DNS_NAME} ')
...
...
if [$hostname_req==1]
argument_aray+=('-hostname $MY_PROFILE')
docker run <<argument_aray>>
I couldn't find any dynamic argument constructor for the shell. Please suggest if anyone has any idea how can achieve this
argv+=( --enhancement "$2" ) && python evaluate.py "${argv[@]}"
. Working fine for me – JOEL Feb 02 '23 at 07:55