0

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

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

1 Answer 1

3

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

if test (id -u) -eq 0
    echo root
else
    echo not root
end
1
  • 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. Commented Jan 28, 2017 at 3:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .