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
else
    echo not root
end
  • 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 acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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