How can I use 'do I have root access?' as a conditional in bash?
问题 I am writing an installation script, and would like it to install in a local directory if the user does not have root access. specifically, I am looking for the code that goes between the carats ( <> ) if [[<do I have root access? = TRUE>]]; then .. install .. else .. install in $HOME/mylib .. fi 回答1: For bash, you can use the EUID variable: if [ "$EUID" == 0 ] ; then ..something.. else ..something else fi For a POSIX-compliant solution, use: if [ "`id -u`" == 0 ] ; then Although be aware