Difference between spaces "and" \ "in bash

Is there a difference between " " and \ in bash?

For example, ls *" "* and ls *\ * will return the same result to me.

+4
source share
2 answers

the version of "" will entail a small load on teensy to analyze the internals of quotes for any potential variables / operators. The backslash version will only be considered as literal space with no additional overhead. The actual processor costs / memory usage time between them will be completely microscopic, however, if they are not inside the cycle, which will be performed kajillions times.

+8
source

The backslash only masks the next character and can be typed faster if you just want to mask it, but it can depend on the keyboard layout and whether you enter 10 fingers blindly or not. I prefer quotes because they are easier to enter.

Disguising each other in and of itself is another difference:

 echo \\ 

prints backslash but

 echo "\" 

will display the symbol "and wait for the quote to close.

 echo \" 

will work and output a quote but

 echo """ 

for the same reason as above, will not.

Some special characters, such as linefeed, formfeed, tab, alert, etc., can only be created with backslashes, but not with quotes, including backslashes.

 /bin/echo -e "\tfoo\abar\bbar\ffoo\nbar\rfoo" 

See man echo for a complete list.

This is not only true for echo , but also for many things you can do in scripts that work with strings.

0
source

All Articles