[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: posix-compliant (ash-compliant) test for root



David Coe <david@someotherplace.org> wrote:
> In a shell script that tests for root like this: 
> 
>         if [ $UID != 0 ] ; then ...
> 
> it fails if the shell is ash, because $UID is undefined.
> 
> After looking at dh_testroot, I figured out that it could instead do:
> 
>         perl -we 'exit($< == 0)'
>         if [ $? ] ; then ...
> 
> but it's relatively slow.
> 
> Is there a better way?  Thanks.

if [ $(id -u) != 0 ]; then echo yes; fi

-- 
I consume, therefore I am


Reply to: