Shell scripting - suppressing and eliminating error messages

Oliver Fromme olli at lurza.secnetix.de
Fri May 23 15:35:26 UTC 2008


Paul Schmehl wrote:
 > --On Tuesday, May 20, 2008 17:36:26 -0500 Paul Schmehl <pauls at utdallas.edu> 
 > wrote:
 > > if ( ${BATCH} ); then
 > > [...]
 > > 1: not found
 > 
 > Never mind....forgot to use [ ] for test instead of ( ).

If the value of $BATCH is always either 0 and 1, a neat
trick is to define two shell functions:

0() { false; }
1() { true; }

Then you can savely write:

if ( $BATCH ); then

Or even:

if $BATCH; then

Best regards
   Oliver

-- 
Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M.
Handelsregister: Registergericht Muenchen, HRA 74606,  Geschäftsfuehrung:
secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün-
chen, HRB 125758,  Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart

FreeBSD-Dienstleistungen, -Produkte und mehr:  http://www.secnetix.de/bsd

"Clear perl code is better than unclear awk code; but NOTHING
comes close to unclear perl code"  (taken from comp.lang.awk FAQ)


More information about the freebsd-questions mailing list