Is there a way to assert the current "user" is root (i.e. the script was run by root) using the fish shell?

I know for bash you can check the EUID

  • downvoters please leave comment or say where I can ask better, cheers! – rogerdpack Jan 17 '17 at 5:57

Can't do it with just fish. I'd write:

if test (id -u) -eq 0
    echo root
    echo not root
  • 2
    To expand on Glenn's answer you "can't do it with just fish" because fish tries hard not to reinvent the wheel. New builtin commands or variables are added to fish only when it is clear that doing so is better than relying on external commands. In this case the id command will report the current effective or real UID. And since such checks are rare and not performance critical there is no reason to implement it as a builtin command or variable. – Kurtis Rader Jan 28 '17 at 3:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.