【问题标题】:How to escape 2 dollar signs inside a Makefile? [duplicate]如何在 Makefile 中转义 2 美元符号? [复制]
【发布时间】:2019-04-21 13:34:14
【问题描述】:

我正在使用 cURL 从使用基本身份验证的网站获取页面。假设带有凭据的命令行如下所示(注意“pa$$word”中的两个美元符号):

curl -u "username:pa$$word" https://example.com

当我将此命令粘贴到 Makefile 中时,我得到 HTTP/1.1 401 Unauthorised

问题很明显是两个美元符号与 Makefile 的组合,因为:

curl -u "username" https://example.com

有效(只要我在提示符下输入“pa$$word”)。

这在 Bash 中有效(不在 Makefile 中):

   curl -u 'username:pa$$word' https://example.com

我尝试了各种技巧来逃避这些美元符号。到目前为止,我已经尝试过(没有成功):

   curl -u "username:pa\$\$word" https://example.com
   curl -u "username:pa$$$$word" https://example.com
   curl -u "username:{pa$$word}" https://example.com
   curl ---netrc https://example.com # Credentials are in .netrc

对于那些担心我在 Makefile 中以纯文本形式输入密码的投票者 - 有问题的密码是用于公共测试服务器的,该公司已在该公共网页上披露了参与测试所需的所有凭据。

我基本上尝试使用 Makefile 编写测试过程的脚本,而不是使用 ssh 一遍又一遍地键入相同的命令。

注意:有人认为这是关于Escaping in makefile 的更一般问题的重复。但是,我的问题是特别是关于如何在 Makefile 中转义 2 美元符号。一般案例答案如何适用于这个用例并不明显(至少对我来说不是)。

【问题讨论】:

  • 你试过单引号吗?
  • curl -u 'username:pa$$word' https://example.com 在这里工作正常
  • @oguzismail - 我知道,但问题与 Makefile 有关,而不仅仅是 bash(请参阅已编辑的问题)。
  • makefile 中的SHELL 变量是什么?
  • 以纯文本形式存储密码似乎是一个非常糟糕的主意。使用 SSH 或类似的方式。

标签: curl makefile escaping


【解决方案1】:

make 文件中的$$ 替换为$,请尝试以下操作:

curl -u 'username:pa$$$$word' https://example.com

并查看make specification 中的部分。

【讨论】:

    【解决方案2】:

    在双引号内,shell 需要反斜杠以避免美元扩展。

    Makefile 需要加倍的美元才能生成一美元。

    因此,要在 Makefile 中的双引号内使用美元,您必须 both

    rule:
            shell-command ... "pa\$$\$$word" ...
    

    【讨论】:

      猜你喜欢
      • 2017-02-19
      • 2015-06-17
      • 2021-07-01
      • 1970-01-01
      • 2022-11-22
      • 1970-01-01
      • 2010-11-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多