Armin K. wrote:
> On 10/08/2012 06:47 PM, Bruce Dubbs wrote:
>
> Sorry for the delay, I've missed the reply somehow.
>
>>
>> Well what we have now is wrong and what we had before is also wrong.
>> The above is right, but may not be elegant.  It is, however, somewhat
>> educational.
>>

>> It could be collapsed to two physical lines:
>>
>> as_root() { if [ -x /usr/bin/sudo ]; then sudo $*
>>                                         else su -c \\"$*\\"; fi }
>>
>> We only need to change the entity and then the $AS_ROOT to as_root in
>> the 4 places needed.

 >   From what I see, your command would attempt to use either sudo or su
 > even if ran as root user. Maybe some kind of "am I root?" checking
 > should be done there before trying to check for sudo or execute su if
 > sudo is not present.

as_root()
{
   if   [ $EUID = 0 ];        then $*
   elif [ -x /usr/bin/sudo ]; then sudo $*
   else                            su -c \\"$*\\"
   fi
}

export -f as_root

The spacing may be slightly overdone.

   -- Bruce
-- 
http://linuxfromscratch.org/mailman/listinfo/blfs-dev
FAQ: http://www.linuxfromscratch.org/blfs/faq.html
Unsubscribe: See the above information page

Reply via email to