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

Re: test-boolean tool

ms419@freezone.co.uk writes:

> Is there a tool to test strings as boolean values? For instance,
> test-booean true, True, TRUE, T, yes, on, 1, succeed, but test-boolean
> false, False, FALSE, F, no, off, 0, fail?

I'm not aware of any such tool.

> One problem I can't resolve is what it should do on test-boolean
> notaboolean. Better than resulting in some default behavior (true or
> false) on invalid input, would be resulting in an exception. However, my
> foreseen application is in a shell script, the if statement of which
> (AFAIK) won't result in exceptions (an error is failure is false).

Like other tools which return one of three possible states (e.g. grep:
match, no match, error), your tool could return 0 (true), 1 (false), or
2 (error).  It should also print an error message in the latter case.

It might also be a good idea to have command line options to treat
unrecognized input as either true or false, either with or without a
warning message being printed.


Reply to: