3

How do you test if you have administrator privileges in a script for msysgit/Cygwin? On my machine, opening Git Bash as admin and running whoami still outputs James, not root.

I guess you could probably do something like

if touch /C/file.txt && rm /C/file.txt; then
    echo 'Admin!'
else
    echo 'Not admin!'
fi

but that feels very hackish. Is there any better way to do this?

edit: Also tried id and id -G, but they have the same output for admin and regular terminals.

James Ko
  • 25,479
  • 23
  • 92
  • 196

1 Answers1

3

Found a solution from Batch:

if net session &> /dev/null; then
    echo 'Admin!'
else
    echo 'Not admin!'
fi
James Ko
  • 25,479
  • 23
  • 92
  • 196