Let's say you opened a Git Bash console and used it for a time but you forgot if you opened it as Administrator or not.
Is there a way to check this in the current console, without closing and opening it again?
Let's say you opened a Git Bash console and used it for a time but you forgot if you opened it as Administrator or not.
Is there a way to check this in the current console, without closing and opening it again?
Adapted from the thread on how to check for admin rights, run the following:
if [[ $(sfc 2>&1 | tr -d '\0') =~ SCANNOW ]]; then echo Administrator; else echo $USERNAME; fi
If you are running git-bash
as Administrator, it will print Administrator
, otherwise it will print your username.
fi
doing? –
Dongola fi
is the end of the if
block. See mywiki.wooledge.org/BashGuide/… –
Orchestrion My PS1 environmental variable looks like this:
\[\033]0;$TITLEPREFIX:$PWD\007\]\n\[\033[32m\]\u@\h \[\033[35m\]$MSYSTEM \[\033[33m\]\w\[\033[36m\]`__git_ps1`\[\033[0m\]\n$
So off the back of the answer from @daveloyall. I've put this into my .bash_profile
if [[ $(sfc 2>&1 | tr -d '\0') =~ SCANNOW ]]; then
export TITLEPREFIX='ADMIN'
fi
This then prefixes the window title with ADMIN
if you've opened git-bash as administrator.
A reliable way to check if git-bash on Windows is running as admin privilege:
#!/bin/bash
net session 1>/dev/null 2>&1 || printf >&2 "error: please run this script as administrator.\n"
If you want to take into consideration that there might be a Windows which has no net
command (I doubt that), you can check for it:
#!/bin/bash
if type -fq net >/dev/null
then
net session 1>/dev/null 2>&1 || printf >&2 "error: please run this script as administrator.\n"
fi
You can try a linux command, like that:
whoami
This will return your system username
or windows command:
ECHO %USERNAME%
Yes, You can check the current username by using this command:
git config user.name
This will return the username and you can know if it is the Administrator.
© 2022 - 2024 — McMap. All rights reserved.
env | grep SESSIONNAME
. If it's run as Administrator, the command returns nothing. If not, it returnsSESSIONNAME=Console
. But this is just what I have observed from tests. I am not sure if this is the difference caused by running as or not as administrator. I have no idea what SESSIONNAME means. – Enochenol