bash-libraries icon indicating copy to clipboard operation
bash-libraries copied to clipboard

Simplify am_i_root()

Open rasa opened this issue 4 years ago • 0 comments

https://github.com/juan131/bash-libraries/blob/637c5a5a7290397c4ac2efdea032da3e4ecb1cc1/lib/libos.bash#L75-L81 can be simplified to:

am_i_root() { 
  [[ "$(id -u)" = "0" ]]
 } 

or even better:

am_i_root() { 
  (($(id -u) == 0))
}

or ever better:

am_i_root() { 
  ((${EUID:-${UID:-$(id -u)}} == 0))
}

rasa avatar Mar 27 '21 16:03 rasa