Reputation: 41
I have a script which output that :
TAGS Name i-1c69afe325 instance INSTANCE_NAME
I want to take "Name" and "INSTANCE_NAME" and make an environment variable with it.
I tried a lot of things and the last was :
./test2.sh | awk '{system("export "$2"="$5)}'
it did't errored but I don't have any env var.
Any idea ?
PS : if it is important, I try to transform my ec2-tags into environment-variables each time my instance boot.
Thank you a lot for your help
Upvotes: 1
Views: 132
Reputation: 81012
Using the information you can find on Bash FAQ 001 you come up with something like this:
while IFS= read -r tags name i_var instance instance_name; do
declare "$name"="$instance_name"
done < <(./test2.sh)
or with a recent bash
while IFS= read -r tags name i_var instance instance_name; do
printf -v "$name" %s "$instance_name"
done < <(./test2.sh)
Upvotes: 1