【问题标题】:How to set and get variables when working in cmd在cmd中工作时如何设置和获取变量
【发布时间】:2014-09-21 12:14:39
【问题描述】:

我在cmd 工作,使用cURL 发送HTTP GET 和POST 请求。

有很多次我向相同的页面发送请求并且每次都输入它们是一个巨大的痛苦。

我正在尝试弄清楚如何使用set=,以便每次我想使用它们时都可以保存这些 URL。

我试过了

C:\>set page = "http://www.mywebpage.com/api/user/friends"

C:\>page
'page' is not recognized as an internal or external command,
operable program or batch file.

C:\>echo %page%
%page%

但它不会返回页面名称。

我怎样才能完成我所需要的?

【问题讨论】:

    标签: variables batch-file cmd


    【解决方案1】:
    C:\Windows\system32>set page="http://www.mywebpage.com/api/user/friends"
    
    C:\Windows\system32>echo %page%
    "http://www.mywebpage.com/api/user/friends"
    
    C:\Windows\system32>set page=http://www.mywebpage.com/api/user/friends
    
    C:\Windows\system32>echo %page%
    http://www.mywebpage.com/api/user/friends
    

    不要在= 周围使用空格。根据您的需要选择有或没有" 的版本。变量值内部可能包含空格:

    C:\Windows\system32>set page=http://www.mywebpage.com/api/user/my friends
    
    C:\Windows\system32>echo %page%
    http://www.mywebpage.com/api/user/my friends
    

    【讨论】:

      【解决方案2】:

      您正在变量“page”(注意空格)内设置值"http://www.mywebpage.com/api/user/friends",因为您在 = 之前有一个空格。

      因此,您可以使用 %page % 或使用 set page="http://..." 检索值,页面和等号之间没有空格

      【讨论】:

      • 哇,这太疯狂了!我没有意识到空间很重要!
      猜你喜欢
      • 2016-08-08
      • 2010-09-16
      • 2013-01-06
      • 1970-01-01
      • 1970-01-01
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多