I'm using Azure's az
CLI to interact with KeyVault and I don't know how to include a space in the value of the secret I'm trying to set. As of azure cli version 2.0.46, proper syntax for setting a secret is:
az keyvault secret set --vault-name NAME --name SECRET_NAME --value VALUE
If VALUE is "my value" (without quotes), I get an error for too many arguments. If I include the quotes on the command line, they show up in the actual value (in this example, the value will be \"my value\"
. I can put my value in a file and use the -f
flag but this can be inconvenient and sometimes impossible depending on the access permissions with the filesystem.
Is there any other solution to this?
Actually, it could be argued that my original question and attempt wasn't really valid but it's nuanced. It turns out this is a shell variable expansion problem, not an issue with quotes in the az
CLI.
--value VALUE
where VALUE
is "my value"
is NOT the same as --value "VALUE"
where VALUE
is my value
. I was thinking that, after the expansion, they would be the exact same command.
Here are some concrete commands -
az keyvault secret set ... --value $VALUE
when $VALUE
= my value
shows the "expected one argument" error.
az keyvault secret set ... --value $VALUE
when $VALUE
= "my value"
stores \"my value\"
in the vault.
az keyvault secret set ... --value "$VALUE"
when $VALUE
= my value
stores my value
in the vault (as I wanted)
az keyvault secret set ... --value '$VALUE'
when $VALUE
= my value
stores my value
in the vault (same as double quotes)