Hey @koalaman & team!
Love the tool — huge thanks for making it.
Reporting a peculiar (but real!) edge-case for your pleasure. When checking a script which uses aliases, you either get the awesome SC2139 with alias body in double quotes — or enclose the body properly in single quotes — and then, shellcheck misses variable use in the alias.
TL;DR: just see the reproducer, carefully extracted from a big fat "in-the-wild" script.
shellcheck --version or "online"): 0.7.0#!/bin/bash
SSH_OPTS="
-o PasswordAuthentication=no
-o UserKnownHostsFile=/dev/null
-o StrictHostKeyChecking=no
-o LogLevel=quiet
"
shopt -s expand_aliases
alias ohsodirtyssh='ssh -t $SSH_OPTS'
# ...
ohsodirtyssh [email protected] echo "well i'm an example..."
In test.sh line 3:
SSH_OPTS="
^------^ SC2034: SSH_OPTS appears unused. Verify use (or export if used externally).
For more information:
https://www.shellcheck.net/wiki/SC2034 -- SSH_OPTS appears unused. Verify u...
No warning, the variable is in use.
I hit this one too, ironically after following https://github.com/koalaman/shellcheck/wiki/SC2139 to change double to single quotes
There was a hack in place to look up variables from string literals in trap commands, and now the same thing is done for aliases. It's not foolproof, but it covers the most trivial cases like this. Thanks!
Most helpful comment
There was a hack in place to look up variables from string literals in
trapcommands, and now the same thing is done foraliases. It's not foolproof, but it covers the most trivial cases like this. Thanks!