bash - 是否可以将 linux 管道中的值放入 curl 查询字符串参数中?

标签 bash curl

我有一个来自命令的数字输出,让我们说:

 sh -c 'exit 1' ; echo $?
或者
bc <<< "1 + 1"
我需要通过 curl 在 GET 请求中发送它,比如 http://example.com/?value=1
我试过这个:
sh -c 'exit 1' ; echo $? | curl -G -d @- http://example.com/
但它只是得到了一个名称为 1 的参数和 empty值(value)。
我知道我可以这样做:result=`sh -c 'exit 129' ; echo $?` | curl -G -d value=${result} http://example.com但我想保持命令的第一部分不变,只修改管道后的部分。是否可以?

最佳答案

我发现的一种可能的解决方案:

sh -c 'exit 129'; echo $? | xargs -I '{}' curl -G "http://example.com?value={}";

关于bash - 是否可以将 linux 管道中的值放入 curl 查询字符串参数中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67010618/

相关文章:

bash 在 sqlplus + Heredoc 中引用变量替换

linux - 通过 bash 脚本的 Gnuplot

linux - 如何在删除文件之前检查文件是否具有正确的前缀

c++ - 如何找出 libcurl 在 tcp session 中使用的源 tcp 端口

windows - 无法使用 Windows 的 OpenSSL 支持交叉编译 cURL

c++ - 如何在配置中禁用 "compiler does not halt on function prototype mismatch"错误?

bash - 使用 shell 脚本捕获 Impala 中的错误

bash - 基于 bash.how 中的字符串定界符拆分文件?

ios - 将 CURL 转换为 Swift 以在 Alamofire 中使用

PHP Multi Curl curl_multi_select 减慢进程。另一种选择工作得更快但有缺陷?