I'm using SaltStack to run a command that contains a Linux enviornment variable inside a string. The environment variable is $DUO. Example:
export DUO="TESTKEY"
I can run a command such as:
salt computer chocolatey.install app args='/S /V" /qn '"$DUO"'"'
This will actually produce a command like:
'/S /V" /qn TESTKEY"'
It outputs the environment variable which is what I want.
I am now running a bash script that gets the environment variable from the user and places it in the string:
#!/bin/bash
echo "What env do you want to use?: "
read env
i="\$${env}"
echo $i
salt computer chocolatey.install app args='/S /V" /qn '"${i@Q}"'"'
My Bash script takes the users input and automatically places a '$' in front of it. If a user enters input of "DUO", the command will run as:
'/S /V" /qn '$DUO'"'
But I want it to run this:
'/S /V" /qn TESTKEY"'
In the Bash script, how can I escape the i variable properly so that it calls the environment variable $DUO when the command runs?
UPDATE
Here is my actual SaltStack command:
sudo salt computername chocolatey.install duo override_args=True install_args='/S /V" /qn HOST="xxxxxxx.com" RDPONLY="#0" '"$DUO"'"'
Output:
computername:
Chocolatey v0.10.15
Installing the following packages:
duo
By installing you accept licenses for the packages.
duo v0.3
duo package files install completed. Performing other installation steps.
Installing Duo...
Overriding package arguments with '/S /V" /qn HOST="xxxxxxx.com" RDPONLY="#0" TESTKEY"' (replacing '/S /V" /qn HOST="xxxxxxx.com" RDPONLY="#0" "')
Duo has been installed.
The install of duo was successful.
Software installed as 'EXE', install location is likely default.
Chocolatey installed 1/1 packages.
See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
UPDATE 2
I ran the script with debugging on and the Bash script is actually running it as:
+ salt 'computername' chocolatey.install duo override_args=True 'install_args=/S /V" /qn HOST="xxxxx.com" RDPONLY="#0" '\''$DUO'\''"'
UPDATE 3
I've tried expanding the variable name and I get an error.
bad substitution
For example, this gives me that error:
#!/bin/bash
echo "What env do you want to use?: "
read env
i="\$${env}"
echo "${!i}"