0

Everything looks right, and pasting the "echo" output into the aws command works as expected. However, when using the variables on the command line, aws complains about an unclosed delimiter, even though there is (or at least seems to be) a terminating delimiter.

QF1="'DBInstances[*].[DBInstanceIdentifier, " 
QF2="SecondaryAvailabilityZone]'"

echo ${QF1}${QF2} 'DBInstances[*].[DBInstanceIdentifier, SecondaryAvailabilityZone]'

$ aws rds describe-db-instances
--query 'DBInstances[*].[DBInstanceIdentifier, SecondaryAvailabilityZone]'
--output=table


| DescribeDBInstances | +--------------------------+--------------+ | copy-20210720 | None | | uis-clitst-rds-east-db1 | None | | uis-dev-rds-east-db1 | None | | uis-intst-rds-east-db1 | us-east-1c | | uis-prod-rds-east-db1 | us-east-1b | +--------------------------+--------------+

aws rds describe-db-instances --query ${QF1}${QF2}

Bad value for --query 'DBInstances[*].[DBInstanceIdentifier,: Bad jmespath expression: Unclosed ' delimiter: 'DBInstances[*].[DBInstanceIdentifier, ^

RonJohn
  • 1,148

1 Answers1

3
QF1="'DBInstances[*].[DBInstanceIdentifier, " 
QF2="SecondaryAvailabilityZone]'"

# ...

aws rds describe-db-instances --query ${QF1}${QF2}

Take note of the list of expansions the shell will perform first and then launch aws -- because you're not quoting the variables on the last line, you are subject to the effect of 3.5.7 Word Splitting

The command used to launch aws will be (angle quotes added for illustration)

aws rds describe-db-instances --query «'DBInstances[*].[DBInstanceIdentifier,» «SecondaryAvailabilityZone]'»
# ....................................^......................................^.^...........................^

The error message is telling you the truth.

Do this instead:

aws rds describe-db-instances --query "${QF1}${QF2}"
# ....................................^............^

Braces are not a substitute for quotes.

glenn jackman
  • 85,964
  • aws does not like double quotes in it's parameter list; only single quotes. – RonJohn Jul 21 '21 at 19:25
  • The shell will remove the double quotes before launching aws. But they are crucial to build the string properly. You may need to remove the literal single quotes from the QF variables. – glenn jackman Jul 21 '21 at 19:26
  • 1
    Understanding shell expansions is critical to writing bug-free shell scripts. Do spend some time reading the links I gave you. – glenn jackman Jul 21 '21 at 19:28
  • 1
    Thanks @ilkkachu, I've updated the wording a bit – glenn jackman Jul 21 '21 at 19:45
  • OP likely also needs QF1="DBInstances[*].[DBInstanceIdentifier, " or QF1='DBInstances[*].[DBInstanceIdentifier, ' that is, the ' are not meant to be part of the argument passed to aws. – Stéphane Chazelas Jul 21 '21 at 19:57