Skip to content
Vidar Holen edited this page Oct 4, 2015 · 5 revisions

This word is outside of quotes. Did you intend to 'nest '"'single quotes'"' instead'?

Problematic code:

alias server_uptime='ssh $host 'uptime -p''

Correct code:

alias server_uptime='ssh $host '"'uptime -p'"

Rationale:

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
alias server_uptime='ssh $host 'uptime -p''
#                              ^--match--^

The shell, meanwhile, always terminates single quoted strings at the first possible single quote:

#                   v---match--v
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:

#                   v--match---v
alias server_uptime='ssh $host '"'uptime -p'"
#                               ^---match---^

This results in an alias with embedded single quotes.

Exceptions

None.

ShellCheck

Each individual ShellCheck warning has its own wiki page like SC1000. Use GitHub Wiki's "Pages" feature guerraart8 to find a specific , or see Checks.

Clone this wiki locally