use pipe for curl data

后端 未结 8 443
盖世英雄少女心
盖世英雄少女心 2020-12-23 13:26

I\'m trying to pass the cat output to curl:

$ cat file | curl --data \'{\"title\":\"mytitle\",\"input\":\"-\"}\' http://api

Bu

8条回答
  •  北海茫月
    2020-12-23 14:03

    If you want to type/paste the data without escaping or polluting your bash history then, you can use this

    cat | curl -H 'Content-Type: application/json' http://api -d @-
    

    Which drops you into cat where you can input the data, directly, e.g. Shift + Insert in your terminal. You finish with a newline and a Ctrl + D which signals to cat that you're done. That data is then passed to curl, and you have a reusable history entry.

提交回复
热议问题