mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated SC2087 (markdown)
18
SC2087.md
18
SC2087.md
@@ -14,11 +14,23 @@
|
|||||||
|
|
||||||
### Rationale:
|
### Rationale:
|
||||||
|
|
||||||
When the end token of a here document is not quoted, parameter expansions and command substitutions will be expanded. This means that the hostname printed will be that of the client, and not of the server.
|
When the end token of a here document is unquoted, parameter expansion and command substitution will happen on in contents of the here doc.
|
||||||
|
|
||||||
In other words, before sending the commands to the server, the client replaces `$HOSTNAME` with localhost, thereby sending `echo "Logged in on localhost"` to the server.
|
This means that before sending the commands to the server, the client replaces `$HOSTNAME` with localhost, thereby sending `echo "Logged in on localhost"` to the server. This has the effect of printing the client's hostname instead of the server's.
|
||||||
|
|
||||||
By quoting the here token, local expansion will not take place, so the server sees `echo "Logged in on $HOSTNAME"` which is expanded and printed with the server's hostname, which is usually the intention.
|
Scripts with any kind of variable use are especially problematic because all references will be expanded before the script run. For example,
|
||||||
|
|
||||||
|
ssh host << EOF
|
||||||
|
x="$(uname -a)"
|
||||||
|
echo "$x"
|
||||||
|
EOF
|
||||||
|
|
||||||
|
will never print anything, neither client nor server details, since before evaluation, it will be expanded to:
|
||||||
|
|
||||||
|
x="Linux localhost ... x86_64 GNU/Linux"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
By quoting the here token, local expansion will not take place, so the server sees `echo "Logged in on $HOSTNAME"` which is expanded and printed with the server's hostname, which is usually the intention.
|
||||||
|
|
||||||
### Exceptions:
|
### Exceptions:
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user