mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated SC2026 (markdown)
14
SC2026.md
14
SC2026.md
@@ -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.
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user