Defining and using a variable in batch file

前端 未结 4 1588
一向
一向 2020-11-22 16:01

I\'m trying to define and use a variable in a batch file. It looks like it should be simple:

@echo off

set locatio         


        
4条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-22 16:43

    The spaces are significant. You created a variable named 'location ' with a value of
    ' "bob"'. Note - enclosing single quotes were added to show location of space.

    If you want quotes in your value, then your code should look like

    set location="bob"
    

    If you don't want quotes, then your code should look like

    set location=bob
    

    Or better yet

    set "location=bob"
    

    The last syntax prevents inadvertent trailing spaces from getting in the value, and also protects against special characters like & | etc.

提交回复
热议问题