I am trying to execute this script as bash test.sh
#!/bin/bash
for region in "aws ec2 describe-regions --output text | cut -f4";
do
echo -e "\nListing Instances in region:'$region'...";
aws ec2 describe-instances --region $region;
done
But the only output that I get for $region is the print of the command. so it says "Listing Instances aws ec2 describe-regions .. "
How can I fix this ?
for variable in $(anything)is a bad idea, and BashFAQ #1 for a discussion of how to correctly iterate over lines of input one at a time.echo -eis itself better avoided, as it's wildly nonportable (not just between shells, but even between runtime configurations when your shell is known to be bash); see Why is printf better than echo? at Unix & Linux)..shextension on a bash script is not great practice; it implies that it's ashscript, butbashandshare two different languages; also, executable scripts are executables, and executables on UNIX typically don't have extensions at all -- you runls, notls.elf; similarly, one runspip, notpip.py).