From owner-freebsd-questions@FreeBSD.ORG Mon Jan 12 03:07:21 2009 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 EBA1B1065672 for ; Mon, 12 Jan 2009 03:07:21 +0000 (UTC) (envelope-from dan@dan.emsphone.com) Received: from email1.allantgroup.com (email1.emsphone.com [199.67.51.115]) by mx1.freebsd.org (Postfix) with ESMTP id 953578FC0A for ; Mon, 12 Jan 2009 03:07:21 +0000 (UTC) (envelope-from dan@dan.emsphone.com) Received: from dan.emsphone.com (dan-a.emsphone.com [199.67.51.107]) by email1.allantgroup.com (8.14.0/8.14.0) with ESMTP id n0C37InF063618 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sun, 11 Jan 2009 21:07:19 -0600 (CST) (envelope-from dan@dan.emsphone.com) Received: from dan.emsphone.com (smmsp@localhost [127.0.0.1]) by dan.emsphone.com (8.14.3/8.14.3) with ESMTP id n0C37Ipt016841 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sun, 11 Jan 2009 21:07:18 -0600 (CST) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.14.3/8.14.3/Submit) id n0C37HUX016806; Sun, 11 Jan 2009 21:07:17 -0600 (CST) (envelope-from dan) Date: Sun, 11 Jan 2009 21:07:17 -0600 From: Dan Nelson To: Jeffrey Goldberg Message-ID: <20090112030717.GA57874@dan.emsphone.com> References: <7740275E-77AA-45C1-B95E-C1F62D2AAB29@goldmark.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7740275E-77AA-45C1-B95E-C1F62D2AAB29@goldmark.org> X-OS: FreeBSD 7.1-STABLE User-Agent: Mutt/1.5.18 (2008-05-17) X-Virus-Scanned: ClamAV version 0.94.1, clamav-milter version 0.94.1 on email1.allantgroup.com X-Virus-Status: Clean X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.0.2 (email1.allantgroup.com [199.67.51.78]); Sun, 11 Jan 2009 21:07:19 -0600 (CST) X-Scanned-By: MIMEDefang 2.45 Cc: "mail.list freebsd-questions" Subject: Re: bash versus sh test builtin 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: Mon, 12 Jan 2009 03:07:22 -0000 In the last episode (Jan 11), Jeffrey Goldberg said: > The -ne operator for [ in /bin/sh doesn't seem to work as in bash. > Also the bash behavior here is what matches /bin/[ most closely. > > $ /bin/sh > $ if [ $UID -ne 0 ] ; then > > echo not root > > fi > [: -ne: unexpected operator > $ exit > $ echo $SHELL > /usr/local/bin/bash > [jeffrey@dobby ~/src/mount-rsnap]$ if [ $UID -ne 0 ] ; then > > echo not root > > fi > not root > > Does anyone have a recommendation of how to run this simple test in / > bin/sh and how to write tests reasonably portably? UID=$(id -u) if [ $UID -ne 0 ] ; then echo not root fi UID is not a variable set by /bin/sh, which is why the test fails. http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_05_03 -- Dan Nelson dnelson@allantgroup.com