You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Fish Shell中结合curl使用EOF/HEREDOC?

Fish shell中curl类HEREDOC请求的转换方案

方案1:管道传递内容(最通用)

Fish原生不支持Bash风格的<<EOF HEREDOC语法,你原用例中--data @-本身就是curl读取标准输入的参数,直接将请求内容通过管道传递给curl即可,无需额外适配,单内容转换后代码如下:

echo '{}' | curl \
--request POST "https://www.example.com/api/v1/test/delete" \
--header "Content-Type: application/json" \
--data @-

如果是多行复杂请求体,直接写Fish原生支持的多行字符串即可:

echo '{
  "id": 123,
  "operate": "delete",
  "force": true
}' | curl \
--request POST "https://www.example.com/api/v1/test/delete" \
--header "Content-Type: application/json" \
--data @-

方案2:psub进程替换(适配无法读取标准输入的场景)

如果遇到工具不支持读取标准输入、必须传入文件路径的场景,可以使用Fish自带的psub进程替换工具,将内容生成临时文件后传递给对应参数:

curl \
--request POST "https://www.example.com/api/v1/test/delete" \
--header "Content-Type: application/json" \
--data @(echo '{
  "id": 123,
  "operate": "delete",
  "force": true
}' | psub)

变量替换说明

如果需要在请求体中插入Fish变量,用双引号包裹字符串即可实现变量自动展开:

set target_id 456
echo "{
  \"id\": $target_id,
  \"operate\": \"delete\",
  \"force\": true
}" | curl \
--request POST "https://www.example.com/api/v1/test/delete" \
--header "Content-Type: application/json" \
--data @-

内容的提问来源于stack exchange,提问作者Elijah Lynn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 22:15:01