I'm writing a script that searches a bunch of AWS accounts for IP addresses. I'm setting the jq command based on the input of the user.
The error I'm getting is this:
./aws_utils.sh: line 1434: jq -r '.Reservations[].Instances[].PrivateIpAddress': command not found
I'm trying to set the variable that sets the jq command with this code:
echo "Find IP Address in AWS"
echo "Search for Public or Private IP Addresses?"
echo "Enter public/private:"
read -r search_scope
if [[ "$search_scope" = "public" ]]; then
set_search="jq -r '.Reservations[].Instances[].PublicIpAddress'"
elif [[ "$search_scope" = "private" ]]; then
set_search="jq -r '.Reservations[].Instances[].PrivateIpAddress'"
else
echo "Invalid Input"
fi
When the script runs this line of code is when the error occurs:
search_result=$(aws ec2 describe-instances --profile="$aws_env" | "$set_search" | /bin/grep -v null | /bin/grep \"$ip_address\")
If I run the same command on the command line, I don't get an error:
aws ec2 describe-instances --profile=nonprod | jq -r '.Reservations[].Instances[].PrivateIpAddress' | /bin/grep -v null | /bin/grep 10.48.167.228
10.48.167.228
Why is the jq command producing a command not found error in the script?