Home > Blockchain >  Is there how to get a Windows user's full name on a Bash/Shell script file on Git Bash?
Is there how to get a Windows user's full name on a Bash/Shell script file on Git Bash?

Time:12-28

I attempted several tests, running a Perl command and a Command Prompt command on Git Bash, but they were not successful due to the errors.

Remember that I can not use PowerShell on my company's computer because it is blocked. I can use only Command Prompt and Git Bash, but I need only Git Bash and a Bash script. I do not want a Batch file.

I referred to:

I tested on a Shell Script file on Git Bash:

MSYS_NO_PATHCONV=1 net user %USERNAME% /domain |find /I "Nome completo"

I received the error:

find: ‘/I’: No such file or directory
find: ‘Nome completo’: No such file or directory
Could not find username.

For more info, type NET HELPMSG 2221.

Also:

perl -MWin32API::Net -E "Win32API::Net::UserGetInfo('',Win32::LoginName(), 10, my $info = {} ); say $info->{fullName}"

But I received the error:

Can't locate Win32API/Net.pm in @INC (you may need to install the Win32API::Net module) (@INC contains: /usr/lib/perl5/site_perl /usr/share/perl5/site_perl /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5/core_perl /usr/share/perl5/core_perl).
BEGIN failed--compilation aborted.

Is there how to get a full name of a current Windows user on a Bash/Shell script on Git Bash?

CodePudding user response:

In a bash shell, find would be /usr/bin/find, that is C:\Program Files\Git\usr\bin\find.exe, not C:\Windows\System32\find.exe.

In that context (Git bash), you can use grep instead:

MSYS_NO_PATHCONV=1 net user ${USERNAME} /domain | grep -i "Nome completo"

I followed "How do I get the current user's username in Bash?", but the environment variable USERNAME should still be visible in Git bash.
The syntax is just different.

  • Related