From be1a7b633b104f2cd2821c3923d628dd2cb1f97f Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sat, 24 Nov 2018 22:54:53 -0800 Subject: [PATCH] Updated SC2152 (markdown) --- SC2152.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/SC2152.md b/SC2152.md index 2df2f3a..7449540 100644 --- a/SC2152.md +++ b/SC2152.md @@ -21,7 +21,7 @@ myfunc() { In many languages, `return` is used to return from the function with a final result. -In bash, `return` can only be used to signal success or failure (0 = success, 1-255 = failure), more akin to `throw/raise` in other languages. +In sh/bash, `return` can only be used to signal success or failure (0 = success, 1-255 = failure), more akin to `throw/raise` in other languages. Results should instead be written to stdout and captured: @@ -30,7 +30,9 @@ message=$(myfunc) echo "The function wrote: $message" ``` -In functions that return small integers, such as getting the cpu temperature, the value should still be written to stdout. `return` should be reserved for error conditions, such as "can't determine CPU temperature". +In functions that return small integers, such as getting the cpu temperature, the value should still be written to stdout. `return` should be reserved for error conditions, such as "can't determine CPU temperature". Error or failure messages should be written to stderr. + +Note in particular that `return -1` is equivalent to `return 255`, but that `return 1` is the more canonical way of expressing the first possible error code. ### Exceptions: