techgnosis
techgnosis

Reputation: 2019

Bash quotes being tricky

I have this command

aws --profile whatever ec2 describe-instances

The short story is that I no choice but to have this '--profile ' section in this command, but I need to be able to use this feature/bug using quotes:

aws --profile "" ec2 describe-instances

BUT the quotes must also be an environment variable, like so

aws --profile $AWS_PROFILE ec2 describe-instances

But I need that variable to resolve the exact same way as the line above it. I have tried

AWS_PROFILE='""'

and

AWS_PROFILE=

and

AWS_PROFILE=""

And it never resolves the same way. Is there anything I can do?

Upvotes: 0

Views: 42

Answers (1)

Charles Duffy
Charles Duffy

Reputation: 295278

Any quotes you put inside the variable are literal. However, in your desired command aws --profile "" ec2 describe-instances, the quotes are syntactic: That is, they're shell syntax describing how the shell is going to create a literal array of C strings to pass to the execv syscall (and how one of those strings needs to be empty); the quotation marks aren't actually passed to the aws command themselves.

So:

AWS_PROFILE=
aws --profile "$AWS_PROFILE" ec2 describe-instances

...will behave identically to

aws --profile "" ec2 describe-instances

Upvotes: 4

Related Questions