I am struggling to iterate through the graphic cards values and then to add each card at the end of the curl var. the output I am aiming to is:
rtx3060 = $(curl http://0.0.0.0:5000/rtx3060)
rtx3070 = $(curl http://0.0.0.0:5000/rtx3070)
rtx3080 = $(curl http://0.0.0.0:5000/rtx3080)
rtx3090 = $(curl http://0.0.0.0:5000/rtx3090)
rx6700 = $(curl http://0.0.0.0:5000/rx6700)
so I created this for loop but it's not working ,any idea
#!/bin/bash
graphic_cards="rtx3060","rtx3070","rtx3080","rtx3090","rx6700"
set curl_var="curl http://0.0.0.0:5000/"
for name_card in graphic_cards; do
set curl_vars=%curl_var% %name_card%
echo %curl_vars%
done
CodePudding user response:
You can use shellcheck to troubleshoot your script for errors.
Your graphic_cards
is not an array as seems to be intended. You can try this for the expected output.
#!/bin/bash
graphic_cards=("rtx3060" "rtx3070" "rtx3080" "rtx3090" "rx6700")
curl_var="curl http://0.0.0.0:5000/"
for name_card in "${graphic_cards[@]}"; do
echo "$name_card = \$(${curl_var}${name_card})"
done