Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 12 Jan 2009 14:16:58 -0500 (EST)
From:      vogelke+unix@pobox.com (Karl Vogel)
To:        freebsd-questions@freebsd.org
Subject:   Re: bash versus sh test builtin
Message-ID:  <20090112191700.03CFFBE56@kev.msw.wpafb.af.mil>
In-Reply-To: <7740275E-77AA-45C1-B95E-C1F62D2AAB29@goldmark.org> (message from Jeffrey Goldberg on Sun, 11 Jan 2009 20:08:18 -0600)

Next in thread | Previous in thread | Raw E-Mail | Index | Archive | Help
>> On Sun, 11 Jan 2009 20:08:18 -0600, 
>> Jeffrey Goldberg <jeffrey@goldmark.org> said:

J> if [ $UID -ne 0 ] ; then ...
J> Does anyone have a recommendation of how to run this simple test in /bin/sh
J> and how to write tests reasonably portably?

   I think your best bet for comparisons like this is to use case.  I started
   doing that back in the days when '[' would start a separate program:

     case "$UID" in
       0) echo am root ;;
       *) echo not root ;;
     esac

   I use "test" for things relating to file access:

     die() {
         echo "$@" >& 2
         exit 1
     }

     test -f /etc/passwd || die "Your system is seriously hosed"

-- 
Karl Vogel                      I don't speak for the USAF or my company

If men ruled the world #12: Instead of wasting money on an expensive
engagement ring, your fiancee would get a giant foam hand that said,
"You're #1!"



Want to link to this message? Use this URL: <http://docs.FreeBSD.org/cgi/mid.cgi?20090112191700.03CFFBE56>