Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify am_i_root() #3

Open
rasa opened this issue Mar 27, 2021 · 0 comments
Open

Simplify am_i_root() #3

rasa opened this issue Mar 27, 2021 · 0 comments

Comments

@rasa
Copy link

rasa commented Mar 27, 2021

am_i_root() {
if [[ "$(id -u)" = "0" ]]; then
true
else
false
fi
}

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))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant