Vojt??ch, et al -- ...and then Vojt??ch Zeisek said... % % 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 ... % > > test -s ~/.alias && . ~/.alias || true % > > ^-- SC2015: Note that A && B || C is not if-then-else. C % > > may run when A is true. ... % 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. ... % 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 I would argue against that. The message is accurate and it is warning you about a condition that many may not recognize, perhaps with terrible consequences. % % 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. :-) Since && and || are of equal precedence, encapsulating like that does not change the behavior and thus does not mitigate against the possible problem. Something like A && { B || C } would, though; if A returns false, then nothing on the right is attempted. So for the original problem, I still say that it's bad distribution code and that it should be changed, and if someone will point me in the right direction with instructions suitable for a 5-year-old I will be happy to report it as a bug. For Vojt??ch's specific problem, if you don't mind that you'll always get a true (exit code 0) result out of the .alias line, then you're fine, but rewrite it as test ! -s "$HOME/.alias" || . "$HOME/.alias" if you want to catch any errors out of the .alias file BUT get a 0 whether the file doesn't have any content or runs successfully. HTH & HANN :-D -- David T-G See http://justpickone.org/davidtg/email/ See http://justpickone.org/davidtg/tofu.txt