Dne sobota 20. března 2021 4:47:37 CET, David C. Rankin napsal(a):
On 3/18/21 3:09 AM, Vojtěch Zeisek wrote:
$ shellcheck -o all ~/.bashrc
In /home/vojta/.bashrc line 20: test -s ~/.alias && . ~/.alias || true
^-- SC2015: Note that A && B || C is not if-then-else. C may run when A is true. ^------^ SC1090: Can't follow non-constant source. Use a directive to specify location. I believe you want
test -s /home/vojta/.alias && . /home/vojta/.alias || true
The problem is with '~' expansion in a .bashrc which can have unwanted consequences if the account or a script is accessed vi su or sudo and you don't specifically have --norc set to prevent invoking the bashrc as the other user.
You have the same problem if you use $HOME instead of the absolute path for the user's home.
See if that helps with shellcheck.
Interestingly it's same: $ shellcheck -x -o all ~/.bashrc In /home/vojta/.bashrc line 19: test -s "${HOME}"/.alias && . "${HOME}"/.alias || true ^-- SC2015: Note that A && B || C is not if-then- else. C may run when A is true. ^--------------^ SC1090: Can't follow non- constant source. Use a directive to specify location. For more information: https://www.shellcheck.net/wiki/SC1090 -- Can't follow non-constant source.... https://www.shellcheck.net/wiki/SC2015 -- Note that A && B || C is not if- t... IMHO the SC2015 is rather false positive as adding # shellcheck source=/home/vojta/.alias line before fixes it, https://github.com/koalaman/shellcheck/wiki/SC1090 I'm not sure if there can't be better syntax anyway... It seems the real syntactical problem is SC2015 "A && B || C is not if-then- else. C may run when A is true." https://github.com/koalaman/shellcheck/wiki/ SC2015 Editing it as # Alias # shellcheck source=/home/vojta/.alias { test -s "${HOME}"/.alias && . "${HOME}"/.alias; } || true seems to be the correct syntax --- at least id doesn't report any ShellCheck warning --- I'm just unsure if this is the desired behaviour. :-) -- Vojtěch Zeisek https://trapa.cz/ Komunita openSUSE GNU/Linuxu Community of the openSUSE GNU/Linux https://www.opensuse.org/