In the script below, I can't seem to make $var1 expand in the second statement. I've tried $var1, ${var1}, echo $var1 and '$var1'. It is inside a few sets of quotes and parentheses which I guess is what is causing the problem. Any ideas?#!/bin/bash# Get the AutoScalingGroupName for the NameNode ASGvar1=$(aws cloudformation list-stack-resources --stack-name abc123 | jq '.StackResourceSummaries[] | select(.ResourceType==AWS::AutoScaling::AutoScalingGroup)' | jq '.PhysicalResourceId' | tr -d '' | grep nn); echo $var1var2=$(aws autoscaling describe-auto-scaling-instances | jq -r '.AutoScalingInstances[] | select(.AutoScalingGroupName == $var1) | select(.AvailabilityZone == us-east-1a) .InstanceId'); echo $var2
Variable expansion inside parentheses and quotes
bash;shell script;quoting;variable
Variables in single quotes are not expanded.  Try this...var2=$(aws autoscaling describe-auto-scaling-instances | jq -r '.AutoScalingInstances[] | select(.AutoScalingGroupName == '$var1') | select(.AvailabilityZone == us-east-1a) .InstanceId'); echo $var2