Bash script: Use string variable in curl JSON Post data

后端 未结 3 849
小蘑菇
小蘑菇 2020-11-30 10:04

I want to send a json request and embedd a variable in the post data. I did a little research and I came up with the single quotes around the variable.

    #         


        
3条回答
  •  盖世英雄少女心
    2020-11-30 10:47

    My suggestion:

    #!/bin/bash
    FILENAME="/media/file 2.avi"
    curl -i -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "method": "Player.Open", "params":{"item":{"file":"'"$FILENAME"'"}}}' http://192.167.0.13/jsonrpc
    

    The differences are hyphen in -d (instead of a dash) and double quotes around $FILENAME.

提交回复
热议问题