Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 12 Jan 2009 14:16:58 -0500 (EST)
From: (Karl Vogel)
Subject:   Re: bash versus sh test builtin
Message-ID:  <>
In-Reply-To: <> (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 <> 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 ;;

   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: <>