S
santosh07bec
Guest
Hi guys,
I have written a big automation script for my company's servers. While writing script i found an issue with while loop and i am not able to find explanation for it, although i have found another way to work around it, but still i wonder what might be the reason which gives the result unexpected, Please take a look on the below piece of Bash code...
#!/bin/bash
flag=0
cat /tmp/instanceid.txt | while read id eip garbage
do
if [ "$id" = "i-ab7178c1" ]
then
ec2-start-instance -O accesskey -W key "i-ab7178c1"
flag=1
break
fi
done
echo "The flag contains value = $flag"
Its a small part of my code which i wanted to use to automate the starting of instances.
Assume that the if condition is fine and satisfies the condition once while executing the code and there in no problem the "ec2-start-instance" command, we can expect that the output of the echo as "The flag contains value = 1"; but if u execute the above code, you wont get value of the flag variable as 1 ever it will always print 0 irrespective of if condition.
Can anybody explain why it is so.
Thanks in advance.
Regards,
Santosh
I have written a big automation script for my company's servers. While writing script i found an issue with while loop and i am not able to find explanation for it, although i have found another way to work around it, but still i wonder what might be the reason which gives the result unexpected, Please take a look on the below piece of Bash code...
#!/bin/bash
flag=0
cat /tmp/instanceid.txt | while read id eip garbage
do
if [ "$id" = "i-ab7178c1" ]
then
ec2-start-instance -O accesskey -W key "i-ab7178c1"
flag=1
break
fi
done
echo "The flag contains value = $flag"
Its a small part of my code which i wanted to use to automate the starting of instances.
Assume that the if condition is fine and satisfies the condition once while executing the code and there in no problem the "ec2-start-instance" command, we can expect that the output of the echo as "The flag contains value = 1"; but if u execute the above code, you wont get value of the flag variable as 1 ever it will always print 0 irrespective of if condition.
Can anybody explain why it is so.
Thanks in advance.
Regards,
Santosh