-
Notifications
You must be signed in to change notification settings - Fork 1.8k
SC2026
Joachim Ansorg edited this page Jul 5, 2024
·
6 revisions
alias server_uptime='ssh $host 'uptime -p''
alias server_uptime='ssh $host '"'uptime -p'"
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.
None.