In "Quotes", you learned that quotes keep spaces, and that single quotes "do the same job here". There is one difference. It is about $.
| Keeps spaces | Puts in $VARIABLE values | |
|---|---|---|
Double quotes "..." | Yes | Yes |
Single quotes '...' | Yes | No. Every character stays as you typed it |
text
learner@tidepool:~$ RELEASE=v2
learner@tidepool:~$ echo "release $RELEASE"
release v2
learner@tidepool:~$ echo 'release $RELEASE'
release $RELEASE"release $RELEASE"
release v2
'release $RELEASE'
release $RELEASE
Which one to use
- Double quotes around a variable, so that its value stays one argument:
cat "$FILE". - Single quotes when the text must stay exactly as it is, also with
$:echo 'cost: $5'.
Wildcards also do not work inside either kind of quotes. echo "*.txt" writes *.txt.