🔍 See Original Answer on Ask Ubuntu 🔗
What is the difference between echo $var and echo "$var"
August 23, 2018
November 24, 2022
Copy to clipboard: false
There is no difference between
echo $var and
However for other commands such as
ls (list files) there could be a big difference.
Try this in your terminal:
$ touch "File A" $ var="File A" $ ls $var ls: cannot access 'File': No such file or directory ls: cannot access 'A': No such file or directory $ ls "$var" File A
The double quotes
" tells Linux to treat everything in between as a single entity. Without the double quotes everything inside is treated as separate entities delineated by spaces.
So in the first example
$var is two different things “File” and “A”.
In the second example
"$var" is one thing
echo command automatically processes a single word or multiple words until the end of the line as one thing. Many other commands expect one or many things.