[Toybox] Testing: how to check return code

Andrew Ilijic ilijic.andrew at gmail.com
Wed Oct 30 06:39:40 PDT 2019


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



More information about the Toybox mailing list