All Questions
15 questions
0
votes
2
answers
236
views
Why is echo "\*" the same as echo "\\*"
Title.
echo "\*" has the exact same output as echo "\\*", \*. I am using GNU bash 5.2.15.
I expected echo "\\*" to output \*, but I do not know why echo "\*" ...
0
votes
1
answer
32
views
how to arrange quotes in this bash command
my_cmd --attr1 $(($1-$2)) --attr2 $(($1-$2+$3)) --attr3 $(($2+1))
I have this command and I would like to debug it (put it in echo and see how command will look like) but I am struggling with ...
3
votes
1
answer
3k
views
Shell command executed differently in a terminal and script
The following sequence of commands
ch=`echo "b_d" | sed 's/_/\\\\\\\\_/'`
echo $ch
when executed in a terminal or via source give an output
b\\_d
When ran as a scipt
sh script.sh
where the script ...
2
votes
2
answers
1k
views
Why does the command echo `echo \\\z` output \z?
The command echo $(echo \\\z) is from the book
, I don’t understand why it outputs
\z
I think it should output
z
1
vote
2
answers
3k
views
Why echo command does not need "-e" option when escaping "$" character with a backslash
This is regarding bash builtin echo. Per Bash documentation the -e option enables interpretation of backslash escapes.
If I execute echo "Total Amount \$500", I see the expected output Total ...
5
votes
3
answers
18k
views
Echo new line and string beginning \t
Sure, echo -e can be used so that \n is understood as a new line. The problem is when I want to echo something beginning with \t e.g. "\test".
So let's say I want to perform echo -e "test\n\\test". I ...
7
votes
2
answers
977
views
Why does dash's echo expand \\\\ differently to bash's echo?
I have a little open source project that for various reasons I've tried to write in reasonably portable shell script. Its automated integration tests check that hostile characters in path expressions ...
13
votes
2
answers
3k
views
What is the difference between single quoted $'string' and double quoted $"string" in bash?
I was trying to execute new line using echo and tried following two commands:
First command:
echo $'Hello World\nThis is a new line'
Response:
Hello World
This is a new line
Second command:
echo $"...
0
votes
2
answers
173
views
trying to escape quotes
I have tried numerous ways to print this line in a script:
alias myname='export PATH="/path/to/bin:$PATH"'
All of them have different problems.
The last I tried (and remember!) is:
printf '%s' '%s\...
6
votes
2
answers
3k
views
What are the effects of double quotes in echo statements? [closed]
When writing a Bash script that contains messages for the user, I can write
echo Processing files...
or
echo "Processing files..."
In this and many other cases, the output will be the same....
3
votes
2
answers
8k
views
Escape characters from echo -e
I have the following in my .bashrc file I use for a log:
function log(){
RED="\e[0;31m"
RESET="\e[0m"
echo -e "${RED}$(date)" "${RESET}$*" >> "$HOME"/mylog.txt
}
But when I do something ...
2
votes
1
answer
2k
views
Bash - syntax in echo
When using /bin/bash, what is the difference between the following two cases:
echo $IFS
echo "$IFS"
I observe different outputs.
9
votes
7
answers
19k
views
echo \\* - bash backslash escape behavior, is it evaluated backwards?
So in bash,
When I do
echo \*
*
This seems right, as * is escaped and taken literally.
But I can't understand that,
when I do
echo \\*
\*
I thought the first backslash escaped the second one ...
14
votes
2
answers
8k
views
Quoted vs unquoted string expansion
for i in $(xrandr); do echo "$i" ; done
for i in "$(xrandr)"; do echo "$i"; done
for i in "$(xrandr)"; do echo $i; done
I understand why 1 differs from 2. But why does 3 give a different output from ...
5
votes
2
answers
661
views
Why am I observing different behaviour of echo?
I observed the below behavior of echo
#!/bin/bash
x=" hello"
echo $x
echo "$x"
Now when I run the above code I get
ronnie@ronnie:~$ bash test.sh
hello
hello
ronnie@ronnie:~$
So, can someone ...