Skip to content

Simplify am_i_root() #3

@rasa

Description

@rasa

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))
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions