I have a function in bash that creates volumes and then attaches them to a newly created aws instance.
I need to ask the user how many volumes to create, and then attach it to the instance with this line:
aws ec2 attach-volume --volume-id "${volumes[i]}" --instance-id "$tag_instance_id" --device "$device" --profile="$aws_key"
I am using a loop to iterate through the volumes that are created. I need to assign a device to the instance with would be of the form:
/dev/xvdf
Then the next volume would be /dev/xvdg, /dev/xvdf depending on how many the user asks for.
This is the loop I've created:
printf "Number of volumes to add: "
read -r num_volumes
volumes=()
for (( i=0; i < num_volumes; i++ )); do
...do stuff...
aws ec2 attach-volume --volume-id "${volumes[i]}" --instance-id "$tag_instance_id" --device "$device" --profile="$aws_key"
done
How do I iterate among both the number of volume ($i) and the device values from /dev/xvd{f..z} in the same line? The volume number ($i) has to correspond to the device name (/dev/xvdf or whatever).