From owner-freebsd-questions@FreeBSD.ORG Mon Jan 12 03:53:03 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 A7E48106566C for ; Mon, 12 Jan 2009 03:53:03 +0000 (UTC) (envelope-from freebsd@optimis.net) Received: from mail.optimis.net (mail.optimis.net [69.104.191.124]) by mx1.freebsd.org (Postfix) with ESMTP id 7B6FB8FC12 for ; Mon, 12 Jan 2009 03:53:03 +0000 (UTC) (envelope-from freebsd@optimis.net) Received: from marvin.optimis.net (marvin.optimis.net [192.168.1.3]) by mail.optimis.net (8.14.2/8.14.2) with ESMTP id n0C3EUWj031223 for ; Sun, 11 Jan 2009 19:14:30 -0800 (PST) (envelope-from freebsd@optimis.net) Received: from marvin.optimis.net (localhost [127.0.0.1]) by marvin.optimis.net (8.14.2/8.14.2) with ESMTP id n0C3ETuU047578 for ; Sun, 11 Jan 2009 19:14:29 -0800 (PST) (envelope-from freebsd@optimis.net) Received: (from george@localhost) by marvin.optimis.net (8.14.2/8.14.2/Submit) id n0C3ETjP047577 for freebsd-questions@freebsd.org; Sun, 11 Jan 2009 19:14:29 -0800 (PST) (envelope-from freebsd@optimis.net) Date: Sun, 11 Jan 2009 19:14:29 -0800 From: George Davidovich To: freebsd-questions@freebsd.org Message-ID: <20090112031429.GA42596@marvin.optimis.net> 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> User-Agent: Mutt/1.5.18 (2008-05-17) 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:53:03 -0000 On Sun, Jan 11, 2009 at 08:08:18PM -0600, Jeffrey Goldberg wrote: > 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 if [ $(id -u) -ne 0 ]; then ... As to why your test isn't working as expected, rewrite your script to read: #!/bin/sh echo $UID and you'll discover that UID is a bash environmental variable. > and how to write tests reasonably portably? That's a different question, and merits a much longer discussion probably better had elsewhere. I'd suggest comp.unix.shell. -- George