From owner-freebsd-questions@FreeBSD.ORG Tue May 20 23:01:18 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D4C1C1065686 for ; Tue, 20 May 2008 23:01:18 +0000 (UTC) (envelope-from cswiger@mac.com) Received: from mail-out3.apple.com (mail-out3.apple.com [17.254.13.22]) by mx1.freebsd.org (Postfix) with ESMTP id C460A8FC34 for ; Tue, 20 May 2008 23:01:18 +0000 (UTC) (envelope-from cswiger@mac.com) Received: from relay13.apple.com (relay13.apple.com [17.128.113.29]) by mail-out3.apple.com (Postfix) with ESMTP id 803102C4BF95; Tue, 20 May 2008 16:01:18 -0700 (PDT) Received: from relay13.apple.com (unknown [127.0.0.1]) by relay13.apple.com (Symantec Mail Security) with ESMTP id 5DB6E280A2; Tue, 20 May 2008 16:01:18 -0700 (PDT) X-AuditID: 1180711d-a9b93bb000000ed7-b9-4833583e39e0 Received: from cswiger1.apple.com (cswiger1.apple.com [17.227.140.124]) by relay13.apple.com (Apple SCV relay) with ESMTP id 4B1FF28092; Tue, 20 May 2008 16:01:18 -0700 (PDT) Message-Id: <4913B976-E1A7-4B46-A63B-392C6B0EA146@mac.com> From: Chuck Swiger To: Paul Schmehl In-Reply-To: <83C71638D3A682FC1B026581@utd65257.utdallas.edu> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v919.2) Date: Tue, 20 May 2008 16:01:18 -0700 References: <83C71638D3A682FC1B026581@utd65257.utdallas.edu> X-Mailer: Apple Mail (2.919.2) X-Brightmail-Tracker: AAAAAA== Cc: FreeBSD Questions Subject: Re: Shell scripting - suppressing and eliminating error messages X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 May 2008 23:01:18 -0000 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