Bash:卷曲多行,将输出写入文件

时间:2018-06-02 13:06:11

标签: bash

我有一个简单的bash脚本,用几个参数调用cURL。

我需要在文件中写入输出(也覆盖)。但我做不到。

调用本身有效,但我只有一个空文件(答案是json,我可以在shell上读取该回显)

提前感谢您的帮助

第一次尝试

 curl -X POST "https://www.example.com"\
        -H "X-Auth-Email: $email"\
        -H "X-Auth-Key: $auth_key"\
        -H "Content-Type: application/json"\
        --data '{"name":"'$name'","surname":"'$surname'"}'
        >> id.txt
        echo

第二次尝试

curl -X POST "https://www.example.com"\
            -H "X-Auth-Email: $email"\
            -H "X-Auth-Key: $auth_key"\
            -H "Content-Type: application/json"\
            --data '{"name":"'$name'","surname":"'$surname'"}'
            o id.txt
            echo

1 个答案:

答案 0 :(得分:2)

curl -X POST "https://www.example.com"\
        -H "X-Auth-Email: $email"\
        -H "X-Auth-Key: $auth_key"\
        -H "Content-Type: application/json"\
        --data '{"name":"'$name'","surname":"'$surname'"}'\
        -o id.txt