Dne neděle 21. března 2021 6:02:42 CET, David T-G napsal(a):
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.
AFAIK '{ A && B; } || C' means that *if both* A and B are TRUE, C is skipped; and *if any of* A or B is FALSE, then C is executed, isn't it?
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
If it is, it can be reported at https://bugzilla.opensuse.org/ and fixed, I'm just still unsure what's the best alternative, thought... :-(
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,
It's not really my specific problem, I was just wondering if default code shipped by openSUSE is the bes one. :-)
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.
Hmmm... -- Vojtěch Zeisek https://trapa.cz/ Komunita openSUSE GNU/Linuxu Community of the openSUSE GNU/Linux https://www.opensuse.org/