git-bash 中的 curl 命令
curl command in git-bash
我有一个用 bash 编写的脚本,并在 Linux (CentOS 7) 和 MacOS 上进行了测试。该脚本使用 cURL
与 REST API 兼容的数据平台 (XNAT) 进行交互。
我希望 Windows 用户可以在 git-bash 中使用与 Git 打包的相同脚本 for Windows。不幸的是,在 git-bash.
中使用 cURL
时似乎存在问题
我对 cURL
的第一次使用是检索 JSESSION cookie:
COOKIE=`curl -k -u $USERNAME https://theaddress/JSESSION`
在 Linux 上,这会要求用户输入密码并将 cookie 存储在 COOKIE
中。
在 git-bash 中,发出命令挂起,直到使用“ctrl + C
”中断它。奇怪的是,此时显示了密码查询消息,但为时已晚,脚本已终止。
我怀疑这可能与 CR
或 LF
问题有关,但无法找到我了解的相关信息。
欢迎任何指点!
谢谢
编辑:
如果我像这样在命令中传递密码,上面的命令似乎工作正常:
COOKIE=`curl -k -u $USERNAME:$PASSWORD https://theaddress/JSESSION`
但是,正如这里指出的那样:
Using cURL with a username and password?
我宁愿避免让用户输入他们的密码作为命令参数。
所以现在的问题是 "why is cURL
not prompting for a password when I use the first command?" when in git-bash on Windows,而该命令在 Linux 或 MacOS 中的行为符合预期:
COOKIE=`curl -k -u $USERNAME https://theaddress/JSESSION`
回答完我自己的问题,希望这对其他人有用。
根据此线程,当从 git-bash 中 运行ning cURL
时,此问题似乎是一个已知问题:
https://github.com/curl/curl/issues/573
具体请参阅 dscho 于 30 Dec 2015 的回答:
The problem is the terminal emulator we use with Git Bash since Git for Windows 2.5, MinTTY.
This terminal emulator is not associated with a Win32 Console, therefore the user does not see anything when cURL wants to interact with the user via said Console.
此问题有解决方法,记录在此处:
https://github.com/git-for-windows/build-extra/blob/master/ReleaseNotes.md#known-issues
解决方法是 运行 通过 winpty 卷曲如下:
winpty curl [arguments]
毕竟 CR
或 LF
不是问题。
Soooo,git-bash 可能不是 magic-bullet (tm) to 运行 my bash Windows 中的脚本零努力。唉……
我有一个用 bash 编写的脚本,并在 Linux (CentOS 7) 和 MacOS 上进行了测试。该脚本使用 cURL
与 REST API 兼容的数据平台 (XNAT) 进行交互。
我希望 Windows 用户可以在 git-bash 中使用与 Git 打包的相同脚本 for Windows。不幸的是,在 git-bash.
中使用cURL
时似乎存在问题
我对 cURL
的第一次使用是检索 JSESSION cookie:
COOKIE=`curl -k -u $USERNAME https://theaddress/JSESSION`
在 Linux 上,这会要求用户输入密码并将 cookie 存储在 COOKIE
中。
在 git-bash 中,发出命令挂起,直到使用“ctrl + C
”中断它。奇怪的是,此时显示了密码查询消息,但为时已晚,脚本已终止。
我怀疑这可能与 CR
或 LF
问题有关,但无法找到我了解的相关信息。
欢迎任何指点!
谢谢
编辑: 如果我像这样在命令中传递密码,上面的命令似乎工作正常:
COOKIE=`curl -k -u $USERNAME:$PASSWORD https://theaddress/JSESSION`
但是,正如这里指出的那样: Using cURL with a username and password? 我宁愿避免让用户输入他们的密码作为命令参数。
所以现在的问题是 "why is cURL
not prompting for a password when I use the first command?" when in git-bash on Windows,而该命令在 Linux 或 MacOS 中的行为符合预期:
COOKIE=`curl -k -u $USERNAME https://theaddress/JSESSION`
回答完我自己的问题,希望这对其他人有用。
根据此线程,当从 git-bash 中 运行ning cURL
时,此问题似乎是一个已知问题:
https://github.com/curl/curl/issues/573
具体请参阅 dscho 于 30 Dec 2015 的回答:
The problem is the terminal emulator we use with Git Bash since Git for Windows 2.5, MinTTY. This terminal emulator is not associated with a Win32 Console, therefore the user does not see anything when cURL wants to interact with the user via said Console.
此问题有解决方法,记录在此处: https://github.com/git-for-windows/build-extra/blob/master/ReleaseNotes.md#known-issues
解决方法是 运行 通过 winpty 卷曲如下:
winpty curl [arguments]
毕竟 CR
或 LF
不是问题。
Soooo,git-bash 可能不是 magic-bullet (tm) to 运行 my bash Windows 中的脚本零努力。唉……