On 2021-03-18 06:09:40 David T-G wrote:
|Vojt??ch, et al -- | |...and then Vojt??ch Zeisek said... |% |... |% # Alias |% test -s ~/.alias && . ~/.alias || true |% |... |% 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... % |% The second warning SC1090 seems like false positive (waiting for some |% ShellCheck update), but the first SC2015 seems like really problematic |% code, but I'm not sure if I fully get what's going on in this |% syntactical cleanup. What should be the super clean correct code here? |% Is this default worth of change? | |I don't like that code at all. It's guaranteed to succeed, whether .alias |exists with a non-zero length and parses happily, or .alias doesn't exist, |or .alias exists AND HITS A FAILURE, which doesn't make sense. | |Much better would be | | test ! -s ~/.alias || . ~/.alias | |(perhaps with an escaped bang) so that when it is sourced you get the |actual result code out of it. | |As for SC1090, the parser can't give a final answer because the flow |depends on executing code. It's simply warning you that the results are |incomplete.
I have a number of places in my .bashrc that source other files. They have no test code around them at all, because I want to know if they don't work; bash complains if something goes wrong, but continues processing the rest of .bashrc. Leslie -- openSUSE Leap 15.2 x86_64