【发布时间】: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 或类似的方式。