diff --git a/SC2181.md b/SC2181.md index 00d1e3b..2aa491c 100644 --- a/SC2181.md +++ b/SC2181.md @@ -14,11 +14,21 @@ fi ### Correct code: ```sh -if ! make mytarget; +if ! make mytarget then echo "Build failed" fi ``` +For the Solaris 10 Bourne shell: +```sh +if make mytarget +then + : +else + echo "Build failed" +fi +``` + ### Rationale: 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. +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: -The default Solaris 10 Bourne shell does not support `!` outside of the `test` command (`if ! mycommand; then ...` returns `!: not found`) \ No newline at end of file +None. \ No newline at end of file