Recommend to read this first: http://wiki.bash-hackers.org/syntax/quoting

With bash you will see 3 types of quoting & in general typing anything in bash you will be in one of these scenarios (your either in quotes: single OR double, or your not in quotes – thats 3 scenerios)

situation 1. without quotes – not being inside quotes is the common bash world – such as typing date +%z – this behaves like weak quotes (variables expansion and escapes work), however spaces usually seperate different arguments
situation 2. weak quotes / double quotes: “” – variables expand & substitutions work, spaces do not seperate different arguments, whole double quote content is seen as one argument
situation 3. strong quotes / single quotes: ” – variables do not expand, escaping doesnt work, and substitutions dont work

With these 3 situations you can make any type of variable you want. With varying double and single quotes in your content if you want.

sidenote:
* variable expansion (get content of variable): ${i} , $i * escaping (avoid normal behavior of command): \' , \" , \$ * substitutions (run command inside and show its output): date $(date)

sidenote: to type a single quotes.

sidenote: to type a double quotes:

sidenote: they differ on '\''  vs "\""  thats because situation 3 ignores escapes and situation 2 doesnt ignore escapes.

ideally: each none-escaped single quote needs a partner. each none-escaped double quote also needs a none-escaped double quotes

sidenote: you can make null chars like this ""  or like this ''

sidenote:
if you see this (its not wrong, its just extra chars):

Study the behavior of these

NOTE: ssh someserver ‘$COMMAND’ would fail because $COMMAND is not defined on the remote side. its neither a variable and its not a filename/command to run. it literally tries to run $COMMAND.

NOTE: sometimes these combinations of quotes and double quotes can get so confusing that I even think bash gets it wrong (maybe it doesnt and im just not smart enough)

Leave a Reply

Your email address will not be published. Required fields are marked *