How to substitute variable contents in a Windows batch file

前端 未结 7 1660
栀梦
栀梦 2021-01-08 00:55

I\'m writing a simple script to substitute text in an environment variable with other text. The trouble I get is with the substituted or substituted text being pulled from o

7条回答
  •  梦谈多话
    2021-01-08 01:36

    The problem with:

    echo %a:%c%=thin%
    

    is that it tries to expand two variables: a: and =thin with a c constant string between them.

    Try this:

    echo echo ^%a:%c%=thin^% | cmd
    

    The first command outputs:

    echo %a:fat=thin%
    

    which is piped into a second command shell for evaluation.

提交回复
热议问题