tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Changing behaviour of checkyesno (rc.subr)


as already proposed in misc/46757, I'd like to have another behaviour of
checkyesno, which is used for evaluating rc variables.
Current behaviour is to check whether it is some form of "YES" and if so,
returns 0. In case of explicit "NO", it returns a 1.
If there's *anything* else set, it returns a 1 and prints a warning about the
variable not being set properly.

I'd like to change the behaviour to: Return 0 if "YES", 1 on "NO", 2 on empty
(not set) and 1 on not being set properly, in this case print a warning.
If you think further about it, maybe we could even return a 3 in case of no
proper setting (not included in the patch).

Regards, Julian

PS: The check could also be done in the `case`, it doesn't have to be an
explicit if and test.
Index: rc.subr
RCS file: /cvsroot/src/etc/rc.subr,v
retrieving revision 1.91
diff -u -r1.91 rc.subr
--- rc.subr     7 Apr 2012 17:28:44 -0000       1.91
+++ rc.subr     30 Jul 2012 22:15:58 -0000
@@ -44,10 +44,14 @@
 # checkyesno var
 #      Test $1 variable, and warn if not set to YES or NO.
 #      Return 0 if it's "yes" (et al), nonzero otherwise.
+#      Return 2 if it is unset.
        eval _value=\$${1}
+       if [ -z "$_value" ]; then
+               return 2
+       fi
        case $_value in
                #       "yes", "true", "on", or "1"

Attachment: signature.asc
Description: PGP signature

Home | Main Index | Thread Index | Old Index