linux - BASH: Check if user is root -
how can check whether user root or not within bash script?
i know can use
[[ $uid -eq 0 ]] || echo "not root"
or
[[ $euid -eq 0 ]] || echo "not root"
but if script invoked via fakeroot, uid , euid both 0 (of course, fakeroot fakes root privileges).
but there way check whether user root? without trying root can (i.e. creating file in /)?
thank you,
fabian
fakeroot sets custom ld_library_path
contains paths libfakeroot
. example:
/usr/lib/x86_64-linux-gnu/libfakeroot:/usr/lib64/libfakeroot:/usr/lib32/libfakeroot
you can use detect if application running inside fakeroot iterating paths , looking libfakeroot
.
sample code:
is_fakeroot=false path in ${ld_library_path//:/ }; if [[ "$path" == *libfakeroot ]]; is_fakeroot=true break fi done echo "$is_fakeroot"
Comments
Post a Comment