I got a simple problem but very boring.
The goal is to write a shell script that run on EC2 instance to exports tags for rest of the script... Something like:
ec2-describe-tags [...]
| while IFS=':' read name value; do
export "$name"="$value"
done
Not so uggly but don't work, of course cause the export is in the while loop, executed in pipe.
My question is: how to write this correctly? Of course I cannot predict names nor numbers of received tags.
Try this:
while IFS=: read name value; do
export $name="$value"
done < <(ec2-describe-instance ...)
A pipeline runs the commands in a subshell, so the variables don't persist when it's done.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With