I'm writing a bash script, where I take in a large number of arguments. It looks something like this:
bash script.sh 713884440 1041 691539599 Digiweb 371449356 Dublin ...
Since there are a large number of arguments, and since the number of arguments differ depending on the situation, I wanted to build a string that takes all the arguments and puts it in this form:
element.713884440="1041" -d element.691539599="Digiweb" -d element.371449356="Dublin"...
I initially tried writing a for loop to do this. For the first iteration of the loop, I thought ${$i}
would first evaluate to $1
, then to 713884440
for i in $(seq 1 2 $#)
do
ENT=$i
VAL=$i+1
ENTRYSTRING="$ENTRYSTRING -d element.${$i}=\"${${i+1}}\"";
done;
This didn't work. And I've tried having the "inner" variable resolve through echo
and eval
, but those didn't work either. How would I accomplish this?