Updated SC2026 (markdown)

Mingye Wang
2015-09-25 10:13:52 -04:00
parent f258d3d4fe
commit eae8fd22e6

@@ -1,4 +1,4 @@
## This word is outside of quotes. Did you intend to 'nest '"'single quotes'"' instead'? ## This word is outside of quotes. Did you intend to `'nest '"'single quotes'"'` instead'?
### Problematic code: ### Problematic code:
@@ -12,23 +12,23 @@
In the first case, the user has four single quotes on a line, wishfully hoping that the shell will match them up as outer quotes around a string with literal single quotes: In the first case, the user has four single quotes on a line, wishfully hoping that the shell will match them up as outer quotes around a string with literal single quotes:
v--------match--------v # v--------match--------v
alias server_uptime='ssh $host 'uptime -p'' alias server_uptime='ssh $host 'uptime -p''
^--match--^ # ^--match--^
The shell, meanwhile, always terminates single quoted strings at the first possible single quote: The shell, meanwhile, always terminates single quoted strings at the first possible single quote:
v---match--v # v---match--v
alias server_uptime='ssh $host 'uptime -p'' alias server_uptime='ssh $host 'uptime -p''
^^ # ^^
Which is the same thing as `alias server_uptime='ssh $host uptime' -p`. Which is the same thing as `alias server_uptime='ssh $host uptime' -p`.
There is no way to nest single quotes. However, single quotes can be placed literally in double quotes, so we can instead concatenate a single quoted string and a double quoted string: There is no way to nest single quotes. However, single quotes can be placed literally in double quotes, so we can instead concatenate a single quoted string and a double quoted string:
v--match---v # v--match---v
alias server_uptime='ssh $host '"'uptime -p'" alias server_uptime='ssh $host '"'uptime -p'"
^---match---^ # ^---match---^
This results in an alias with embedded single quotes. This results in an alias with embedded single quotes.