This question already has answers here:
How to get a variable value if variable name is stored as string?
(10 answers)
Bash - variable variables [duplicate]
(4 answers)
Dynamic variable names in Bash
(19 answers)
Closed 3 years ago.
I have "INSTALLMODE=BASIC" key value pair defined in my config file. And, I am splitting these key value pairs and assigning them as below.
INSTALLMODE=BASIC
key=INSTALLMODE
x=`echo $key`
Now, I want to get value of $x as BASIC. How could I do that.
Thank you.
Related
This question already has answers here:
how to split long lines for fmt.sprintf
(5 answers)
Best practice for long string literals in Go
(5 answers)
indentation style for multi-line string literals
(3 answers)
How do you write multiline strings in Go?
(11 answers)
How to format a multiline string literal [closed]
(2 answers)
Closed 6 months ago.
I had a variable payload, it is too long here just a part.
payload := strings.NewReader("json=%7B%22rent_content_layout%22%3A%22Original%22%2C%22start_verylargetext_enabled%22%3Afalse%2C%22auto_large_mode")
is any way to make the one line var data to multi line or make it human readable using golang, for bash or shell we use \n, is any trick to line break it using golang
Simply do the string concatenation with the + operator and break the string into small parts.
payload := strings.NewReader(
"json=%7B%22" +
"rent_content_layout%22%3A%22" +
"Original%22%2C%22" +
"start_verylargetext_enabled%22%3A" +
"false%2C%22auto_large_mode")
This question already has answers here:
How to slice an array in Bash
(4 answers)
Using ${1:1} in bash
(2 answers)
Bash: all of array except last element
(1 answer)
Closed 3 years ago.
May you please explain what does this mean:
#:1:$#-1
can you provide an exact explanation?
That's a parameter expansion that returns all the positional parameters but the last one.
It's based on ${parameter:offset:length}, where using # as parameter makes it work on positional parameters. The length $#-1 is the number of positional parameters ($#) minus one.
Here's a showcase : https://ideone.com/HKcaNj
This question already has answers here:
Why does String#gsub double content?
(3 answers)
Closed 5 years ago.
I have this code:
"1'2".gsub("'","\\'")
Instead of "1\'2", I get: "122". Why?
You need to use this:
puts "1'2".gsub("'","\\\\'")
It is because "\\'" means the context following the match, which is "2".
This question already has answers here:
ruby operator "=~" [duplicate]
(3 answers)
Closed 9 years ago.
I was wondering if anyone could explain what the =~ operator does in Ruby. I have seen it a few times but am unable to find a proper explanation of it.
It is used to match Regexes against strings:
http://www.ruby-doc.org/core-2.0.0/Regexp.html#method-i-3D-7E
It returns either a Integer value of the first occurrence in the string or if the expression doesn't match the String it returns nil.
This question already has answers here:
Replacing some characters in a string with another character
(6 answers)
Closed 9 years ago.
Does anyone have an idea on how to search and replace in a string? Let's say for example I have a string
string=".blah http://google.com.ph/tabs/1.5.8 setup https://yahoo.com.ph/root/blah"
I want to search for version 1.5.8 and then replace it with 1.5.9. How do i do it in bash?
instring="version 1.5.8"
outstring=${instring//1.5.8/1.5.9}