Added correct code for Bourne shells

Lawrence Velázquez
2024-03-09 01:37:05 -05:00
parent 039b5d42fb
commit 4bf72bc9c9

@@ -14,11 +14,21 @@ fi
### Correct code: ### Correct code:
```sh ```sh
if ! make mytarget; if ! make mytarget
then then
echo "Build failed" echo "Build failed"
fi fi
``` ```
For the Solaris 10 Bourne shell:
```sh
if make mytarget
then
:
else
echo "Build failed"
fi
```
### Rationale: ### Rationale:
Running a command and then checking its exit status `$?` against 0 is redundant. Running a command and then checking its exit status `$?` against 0 is redundant.
@@ -39,6 +49,8 @@ To additionally capture output with command substitution: `if ! output=$(mycomma
This also applies to `while`/`until` loops. This also applies to `while`/`until` loops.
The default Solaris 10 Bourne shell does not support negating exit statuses with `!`, so `! mycommand` tries to invoke a utility named "!" instead. To test for failure, use `if mycommand; then :; else ...; fi` and `until mycommand; do ...; done`.
### Exceptions: ### Exceptions:
The default Solaris 10 Bourne shell does not support `!` outside of the `test` command (`if ! mycommand; then ...` returns `!: not found`) None.