as someone who likes to see the specific exit value (because it's less ambiguous when you see it in a failure than "yes" or "ok" or whatever)...
i suspect the question you have to ask yourself here is "when does that $? get evaluated?". as a stronger hint, "do you get different results if you use \$? or if you use 'quoting' instead of "quoting"?" this, of course, is the argument in favor of || and && --- you might have to think more to understand a _failure_ but you don't have to think much when you're writing it. $? is the opposite. (some tests will always need $? --- the ones that test specific exit values like 126 vs 127 or whatever.) On Wed, Oct 30, 2019 at 6:44 AM Andrew Ilijic <[email protected]> wrote: > > While implementing `-w` for the `ls` command, I coded it so that the > command would fail if the user tried to pass a negative value. I > wanted to test the return code with a negative argument but could not > make it work. I am not great at Bash. If anyone can tell me what I was > doing wrong, I would appreciate it. > > ``` > testing "with -w - Fail on negative" \ > "$IN && ls -w -5 > /dev/null; echo $? && $OUT" \ > "1" "" "" > ``` > The command would fail and return 1 but, in testing it would always > write zero to the file. > > ~Andrew > _______________________________________________ > Toybox mailing list > [email protected] > http://lists.landley.net/listinfo.cgi/toybox-landley.net _______________________________________________ Toybox mailing list [email protected] http://lists.landley.net/listinfo.cgi/toybox-landley.net
