Expand bash variable within quotes [duplicate] - bash

This question already has answers here:
Expansion of variables inside single quotes in a command in Bash
(8 answers)
How to echo variable inside single quotes using Bash?
(2 answers)
Closed 5 years ago.
How can I expand APP_VERSION so that it gets used in the rest of my script? As it is right now, it doesn't expand and show the argument I pass in via the CLI.
APP_VERSION=$2
BOOTSTRAP_RUN='[{"Path":"s3://abc/scripts/emr/deploy_zip.sh ${APP_VERSION}","Name":"Custom action"}]'

Related

Use command line argument in bash script substituted with value from script [duplicate]

This question already has answers here:
Dynamic variable names in Bash
(19 answers)
How to use a variable's value as another variable's name in bash [duplicate]
(6 answers)
Bash - variable variables [duplicate]
(4 answers)
Closed 2 years ago.
I recently started bash scripting and got stuck with a very basic usecase, searched stackoverflow/google but couldn't find a way to achieve what I am trying to do.
I have a script color.sh
#!/bin/bash
Apple="Red"
Orange="Orange"
Banana="Yello"
echo $$1
What I am trying to achieve is print the color of fruit and accept fruit from command line. The output I want is
./color.sh Apple -> Red, but what I get is some random number which I think is process Id.

bash script, want to use '$' without it looking for a variable [duplicate]

This question already has answers here:
Interpolating variables which contain '$' in a bash script
(1 answer)
Difference between single and double quotes in Bash
(7 answers)
Closed 2 years ago.
I need to write a cron job, to send an mqtt message to "homie/$HOSTNAME/$state".
In the case of $HOSTNAME - it needs to use the env variable, but $state - it must use as is.
How would I add "homie/$HOSTNAME/$state" without bash thinking the $state is a variable as well?

Bash -Bad substitution error when evaluating two env variables [duplicate]

This question already has answers here:
creating environment variable with user-defined name - indirect variable expansion
(1 answer)
Dynamic variable names in Bash
(19 answers)
Is it possible to build variable names from other variables in bash? [duplicate]
(7 answers)
Closed 3 years ago.
This is my script:
#!/bin/bash
AREA="DEV"
DEV_AREA_USER="DevAdmin"
TEST_AREA_USER="TestAdmin"
TEST=${$AREA_AREA_USER}
echo ${TEST}
Result: Bad substitution error. Expected result: DevAdmin
How to fix this? I do not want to create a new variable because there are 75 such variables and 75 files to edit. The lesser the better...

Bash expand variable in an another variable [duplicate]

This question already has answers here:
How to use a variable's value as another variable's name in bash [duplicate]
(6 answers)
What does "${!var}" mean in shell script? [duplicate]
(1 answer)
Closed 4 years ago.
I have the following variables
my_country_code="green"
x="country"
echo ${my_$x_code}
bash: ${my_$x_code}: bad substitution
echo should print green as output, but unable to find any technique which will give the correct output
my_x_code="my_${x}_code"
echo ${!my_x_code}

Inserting Variable into sh Script Command [duplicate]

This question already has answers here:
Filename not printing correctly with underscore "_" in Bash [duplicate]
(2 answers)
Error in string Concatenation in Shell Scripting
(3 answers)
bash variable interpolation separate variables by a hyphen or underscore
(3 answers)
When do we need curly braces around shell variables?
(7 answers)
Closed 5 years ago.
#!/bin/sh -f
set proj_dir="OutputDir"
for projname in lib proj1 proj2
do
mv ./scripts/$projname_BYTECODE ./$proj_dir/scripts/$projname
done
A very simple example of what is not working well for me. $projname_BYTECODE is being interpreted as a variable name but _BYTECODE is actually part of the folder name. Suggestions?
Use ${X} instead of $X, so in your example ${projname}_BYTECODE should do the trick. Have a look at this question for more information: When do we need curly braces in variables using Bash?

Resources