Double substituting Unix variable [duplicate] - shell

This question already has answers here:
Dynamic variable names in Bash
(19 answers)
variable variables in sh or dash
(1 answer)
Closed 4 months ago.
I'm trying to get a value of the variable by double substituting inside the string as follows
i=1
df1 ='date_col'
X='value of the string is $df$i'
But getting invalid substitution error
I need the output as follows
echo $X
value of the string is date_col

Related

Bash script to loop through values in a variable [duplicate]

This question already has answers here:
Loop through a comma-separated shell variable
(10 answers)
Loop through an array of strings in Bash?
(21 answers)
Splitting a comma separated string into multiple words so that I can loop through each word
(4 answers)
Closed 1 year ago.
host_list=abc#xyz.com,cde#xyz.com,zbe#xyz.com
I want to write loop in bash script to scroll through each of this host_list & try to grep a particular string 'abc#xyz.com'. if its present then return yes or no

How to append a sting and a variable in BASH [duplicate]

This question already has answers here:
Dynamic variable names in Bash
(19 answers)
How can I generate new variable names on the fly in a shell script?
(6 answers)
Closed 2 years ago.
I have a variable that points at a file called point.c
I would like to temporarily append "A" to "_SRCS" so I can rename the variable and use it in a function as "SRCS".
A_SRCS=point.c
pro="A B"
for x in $pro
do
SRCS=${${x}"_SRCS"}
echo $SRCS #(will point to a function later on..)
done

Set value of string in variable [duplicate]

This question already has answers here:
Indirect variable assignment in bash
(7 answers)
Dynamic variable names in Bash
(19 answers)
Closed 3 years ago.
I want to set FOO="myvar" and set myvar to another variable. Not sure if that makes sense. Example below.
FOO="myvar"
BAR="true true false"
eval $FOO=$BAR <==== Problem line
echo $myvar
I want the last line to print "true true false"

How to add some string between string [duplicate]

This question already has answers here:
Bash insert subnode to XML file
(2 answers)
Environment variable substitution in sed
(12 answers)
Difference between single and double quotes in Bash
(7 answers)
Closed 5 years ago.
I tried to add some string between strings.
I want to add "themev2" to
<SEC_FLOATING_FEATURE_COMMON_CONFIG_CHANGEABLE_UI></SEC_FLOATING_FEATURE_COMMON_CONFIG_CHANGEABLE_UI>
so that the result is
<SEC_FLOATING_FEATURE_COMMON_CONFIG_CHANGEABLE_UI>themev2</SEC_FLOATING_FEATURE_COMMON_CONFIG_CHANGEABLE_UI>
I tried to use
lama="<SEC_FLOATING_FEATURE_COMMON_CONFIG_CHANGEABLE_UI></SEC_FLOATING_FEATURE_COMMON_CONFIG_CHANGEABLE_UI>"
baru="<SEC_FLOATING_FEATURE_COMMON_CONFIG_CHANGEABLE_UI>themev2</SEC_FLOATING_FEATURE_COMMON_CONFIG_CHANGEABLE_UI>
sed -i 's/$lama/$baru/g' /system/etc/floating_feature.xml;
But it does not work :(

Unix variable usage [duplicate]

This question already has answers here:
Lookup shell variables by name, indirectly [duplicate]
(5 answers)
Closed 7 years ago.
If I have 2 variables with values assigned as below -
a=1; s1=555
Can we print 555 using:
$ echo $s`echo $a`
...? My requirement is use variable 'a' in second variable to print final value of s1.
I have tried it already and failed. Is there any way?
Thanks.
Bash has native syntax for indirect evaluation support:
a=1
s1=555
varname="s$a"
echo "${!varname}"

Resources