The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

If you can read me, I'm broken!

Views: 5,143β€…    Votes:  5β€…    βœ… Solution
Tag : bash  
Link: πŸ” See Original Answer on Ask Ubuntu ⧉ πŸ”—

URL: https://askubuntu.com/q/1068366
Title: What is the difference between echo $var and echo "$var"
ID: /2018/08/23/What-is-the-difference-between-echo-_var-and-echo-__var_
Created: August 23, 2018
Upload: April 8, 2024    Layout:  post
TOC: false    Navigation:  false    Copy to clipboard:  false


There is no difference between echo $var and echo "$var".

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 "File A".

The 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.

⇧ What will happen if I install the same package twice, for example the ubuntu-desktop? Purpose of /proc/thread-self?  β‡©