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

posix-compliant (ash-compliant) test for root



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.


Reply to: