How to convert the value of %USERNAME% to lowercase within a Windows batch script?

后端 未结 9 617
暗喜
暗喜 2020-12-09 17:10

I\'m automating some source control software functionality using a dot bat script but given that our svn repos are hosted in a *NIX box, I\'m facing the eternal case problem

9条回答
  •  余生分开走
    2020-12-09 17:14

    When a scripting language is installed then that can be used with a "FOR" to set a variable.

    Any scripting language can be used if it can convert a string to lowercase and output the result.

    An example using Perl 5 :

    @FOR /F %%s IN ('perl -e "print lc(pop)" %USERNAME%') DO @set USERNAME=%%s
    

    An example using PowerShell :

    @FOR /F %%s IN ('powershell -command "(get-item env:'USERNAME').Value.ToLower()"') DO @set USERNAME=%%s
    

    These days, odds are that PowerShell is already installed by default.

提交回复
热议问题