无法在 .sh 脚本中使用“&”作为后台 HTTPie http 请求

Cannot background HTTPie http request with `&` in .sh script

BASH 提示符是如何工作的:

/testproj> http http://localhost:5000/ping/ &
[1] 10733
(env)
/testproj> HTTP/1.0 200 OK
Content-Length: 2
Content-Type: application/json
Date: Sat, 17 Nov 2018 19:27:01 GMT
Server: Werkzeug/0.14.1 Python/3.6.4

{}

... 但在 .sh:

中执行时失败
/testproj> cat x.sh
http http://localhost:5000/ping/ &
(env)
/testproj> ./x.sh
(env)
/testproj> HTTP/1.0 405 METHOD NOT ALLOWED
Allow: GET, HEAD, OPTIONS
Content-Length: 178
Content-Type: text/html
Date: Sat, 17 Nov 2018 19:29:00 GMT
Server: Werkzeug/0.14.1 Python/3.6.4
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>405 Method Not Allowed</title>



<h1>Method Not Allowed</h1>
<p>The method is not allowed for the requested URL.</p>

?

编辑:http 是 HTTPie

编辑:type http 给出 http is hashed (/testproj/env/bin/http)

编辑:只需 http http://www.google.com </dev/null & 即可重现错误(感谢@e36freak)

编辑:来自 IRC 上的 e36freak:

it appears to be an issue with stdin
i get the same error with just http http://www.google.com </dev/null
http wants stdin to be attached to a tty it looks like
for whatever reason
couldn't find it in the man page but i'm sure it's out there

您最喜欢需要包含 --ignore-stdin 选项以防止 httpie 尝试读取它。参见:https://httpie.org/doc#scripting