This question already has answers here:
I just assigned a variable, but echo $variable shows something else
(7 answers)
When to wrap quotes around a shell variable?
(5 answers)
Closed 4 months ago.
I have a variable 'p' which has values 'first second third'
echo $p
first second third
I want to make this output as below
echo $p
first
second
third
Related
This question already has answers here:
Setting an argument with bash [duplicate]
(2 answers)
Closed 5 months ago.
I have a string containing quotes and backslahes:
-options \'{"version": "http"}\'
I would like to initialize a variable PARAM with this string.
How this can be done in bash?
I thought of adding it to an array: PARAMS=(-options \'{"version": "http"}\')
but the output I am getting is: -options '{version: http}' i.e. without the slashes.
Expected output: -options \'{"version": "http"}\'
Can someone please suggest?
This looks ok to me.
test="-client-options \\'{\"quic-version\": \"h3\"}\\'"
echo "$test"
t2=("$test" "etc")
echo ${t2[#]}
Escape every inner " and double escape for a persisting escape
This question already has answers here:
I just assigned a variable, but echo $variable shows something else
(7 answers)
When to wrap quotes around a shell variable?
(5 answers)
Closed 2 years ago.
I've got a string h="aaaa bbb" which contains 2 spaces between aaaa and bbb,and I want to count the number of spaces in it.However,when I try
echo $h|grep -o ' '|wc -l
it shows 1 instead of the desired two.
Is there any way not to treat consecutive spaces in string as one?
This question already has answers here:
How to remove a newline from a string in Bash
(11 answers)
How to remove carriage return from a variable in shell script
(6 answers)
Closed 3 years ago.
file.sh
#!/bin/bash
fileName="Screenshot_$(TZ=GMT-3 date +%Y%m%d_%H%M%S).png"
echo "|$fileName|"
Terminal at Ubuntu 19.04:
> bash file.sh
|Screenshot_20190521_104141.png
|
I want to understand why a new-line is added to the variable at end?
This question already has answers here:
Bash - variable variables [duplicate]
(4 answers)
Using a variable to refer to another variable in Bash
(3 answers)
Closed 4 years ago.
Say I have an env variable:
export foo="bar";
declare z="\$foo";
I want to echo the value of "$z", which should be "bar". But if I run:
echo "$z"
I get this literal:
$foo
and if I run this instead:
echo "$(eval "$z")"
I get bar is not a command.
But instead I am looking to just get
"bar"
as the echoed result.
How can I do that?
This question already has answers here:
I just assigned a variable, but echo $variable shows something else
(7 answers)
Closed 6 years ago.
I have this string:
string="I love spaces"
I would like to print that so that the spaces would remain. echo $string doesn't seem to print the spaces as well.
Desired Output:
I love spaces
Nevermind me fellas. echo "$string" :/