Re: Shell scripting - suppressing and eliminating error messages

2008-05-23 Thread Oliver Fromme
Paul Schmehl wrote:
 > --On Tuesday, May 20, 2008 17:36:26 -0500 Paul Schmehl <[EMAIL PROTECTED]> 
 > wrote:
 > > if ( ${BATCH} ); then
 > > [...]
 > > 1: not found
 > 
 > Never mindforgot 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)
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Shell scripting - suppressing and eliminating error messages

2008-05-20 Thread Jonathan Chen
On Tue, May 20, 2008 at 05:36:26PM -0500, Paul Schmehl wrote:
> I'm using the following construction in a pkg-deinstall script for a port I 
> maintain:
> 
> if ( ${BATCH} ); then

This should read:

if [ -n "${BATCH}" ] ; then

-- 
Jonathan Chen <[EMAIL PROTECTED]>
--
"Irrationality is the square root of all evil"
  - Douglas Hofstadter
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Shell scripting - suppressing and eliminating error messages

2008-05-20 Thread Chuck Swiger

Hi, Paul--

On May 20, 2008, at 3:36 PM, Paul Schmehl wrote:
I'm using the following construction in a pkg-deinstall script for a  
port I maintain:


if ( ${BATCH} ); then

[ ... ]
Why is this error printing to stdout and how can I suppress it?  Or  
is there a flaw in the logic that, if fixed, would resolve this  
problem?



It's happening because the shell normally tries to run the command in  
the if statement, and evaluate the return value.  Your system doesn't  
have a "1" or "0" command, so that produces the "1: not found"  
message.  For /bin/sh, use the test macro instead:


% BATCH=1
% if [ ${BATCH} -gt 0 ]; then echo yeah; fi
yeah
% BATCH=0
% if [ ${BATCH} -gt 0 ]; then echo yeah; fi

Another way to do this is to use string comparisons, especially if env  
variable is supposed to either be defined or not defined, and what the  
value it is set to if defined doesn't matter:


% unset BATCH
% if [ "x${BATCH}" != "x" ]; then echo yeah; fi
% BATCH=1
% if [ "x${BATCH}" != "x" ]; then echo yeah; fi
yeah
% BATCH=0
% if [ "x${BATCH}" != "x" ]; then echo yeah; fi
yeah

Regards,
--
-Chuck

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Shell scripting - suppressing and eliminating error messages

2008-05-20 Thread Paul Schmehl
--On Tuesday, May 20, 2008 17:36:26 -0500 Paul Schmehl <[EMAIL PROTECTED]> 
wrote:



I'm using the following construction in a pkg-deinstall script for a port I
maintain:

if ( ${BATCH} ); then

The idea is, if you type make BATCH=1 deinstall, the port will deinstall
without running an interactive portion of the pkg-deinstall script.  If you
type make deinstall, the pkg-deinstall script runs.

The script works, but, when you use BATCH=1, it generates an error message:

# make BATCH=1 deinstall clean
===>  Deinstalling for security/sguil-server
===>   Deinstalling sguil-server-0.7.0_1
Stopping sguild..
sguild not running?
1: not found

Why is this error printing to stdout and how can I suppress it?  Or is there
a flaw in the logic that, if fixed, would resolve this problem?


Never mindforgot to use [ ] for test instead of ( ).  My perl is getting in 
the way of my shell. :-(


--
Paul Schmehl
As if it wasn't already obvious,
my opinions are my own and not
those of my employer.

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"