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
Related
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
This question already has answers here:
Create string with trailing spaces in Bash
(2 answers)
Bash LeftPad String with spaces inside variable
(1 answer)
Closed 2 years ago.
Is there a pure bash way to add trailing whitespaces with something like parameter substition in the example above I am using printf in conjunction with command substition witch is not that performant
declare -ir _CONST_VARIABLE_LENGTH='30' _CONST_SUBTRACTOR='3'
declare some_var='here is a string'
declare new_var
new_var="$(printf "%-$((_CONST_VARIABLE_LENGTH-_CONST_SUBTRACTOR))s" "$some_var")"
# what i want, but doesn't work
# ${var:0:LENGTH} only goes till actually length and won't add something if LENGTH is greater than actual var lenght
new_var="${some_var:0:$((_CONST_VARIABLE_LENGTH-_CONST_SUBTRACTOR))}"
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
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 would like to do in bash something I was doing with perl years ago
$4 (value from a script) can have the value "S" or "U"
I have:
DirectoryU="$Directory/*.$2"
DirectoryS="$Directory/area $3/*.$2"
and I want to define "DirectoryC" to something like:
DirectoryC=Directory$4
but there I dont want DirectoryC=DirectoryU (or DirectoryS) I want DirectoryC to have the value of DirectoryU (or DirectoryS) so after I can base my script on $DirectoryC ...
Does it make sense?
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 :(