Why new line is added to variable at end? [duplicate] - bash

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?

Related

Move character in to a new line in bash [duplicate]

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

How to use sed command with variable [duplicate]

This question already has answers here:
Difference between single and double quotes in Bash
(7 answers)
How to use variables in a command in sed?
(4 answers)
Closed 5 months ago.
when I try to delete particular lines in my file using shellscrpit I use below command, It's not working, So can anyone help me on same.
sed -i '${lineNumber}d' <filename>

How to wrap a path with double quotes? [duplicate]

This question already has answers here:
Use output of bash command (with pipe) as a parameter for another command
(4 answers)
When to wrap quotes around a shell variable?
(5 answers)
Closed 1 year ago.
I have the path of git --exec-path | sed 's#/#\\#g', I want to use explorer to open this path, like explorer "path", pseudocode: git --exec-path | sed 's#/#\\#g' | explorer "path", how to implement the last pipe?

shell script count consecutive spaces [duplicate]

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?

sed with argument variables in shell script [duplicate]

This question already has answers here:
How can I extract a predetermined range of lines from a text file on Unix?
(28 answers)
Shell variables in sed script [duplicate]
(5 answers)
Closed 6 years ago.
I want to write a script that extract lines from line n to m of the input.
doit.sh:
sed -n -e '$1,$2p' input.txt
./doit.sh 3 10
But it gave me an error sed: -e expression #1, char 2: unknown command: `2'. What went wrong?

Resources