The Concept Of Quotation In Bash VS Posh
1 min readNov 19, 2021
The aim of this pageđź“ťis to note the difference in single VS double quotes in bash and posh (PowerShell) which articulates a general concept of quotation.
Basically, the question is how should a machine answer the question say $your_name
- In single quotes, it says
$your_name
- it is repeating the symbol without evaluation - In double quotes, it says
pavol
- it is evaluating the symbol and returning its meaning - SICP covers this at this point — https://youtu.be/X21cKVtGvYk?t=1098
1. identical use of quotes
- with single quotes, variables/symbols are not evaluated, and instead their names are treated as literals
â–¶ $your_name="pavol"
â–¶ echo '$your_name'
$your_name
â–¶ echo "$your_name"
pavol
- same for bash
>>> read -p "Your note:" note
Your note:f.o.o.b.a.r
>>> echo '$note'
$note
>>> echo "$note"
f.o.o.b.a.r
2. different escape signs
- if you want to print single quotes as literals themselves you have to escape them
- they are special characters, not literals for the interpreter
- here is a difference
- in posh, you escape with a backtick
â–¶ echo `'$your_name`'
'pavol'
- in bash, you escape with a backslash
>>> your_name=pavol
>>> echo \'$your_name\'
'pavol'