In a bash script i want to get date dynamically and send it along with the curl call.
i have got the date from the user in the bash script and in the script am making the below curl call. am already passing the request params using a separate file as below. How do i pass the date? i have tried like $date, but it is not working, even tried "'$date'".
The below is my curl call:
curl -O -X POST -H "Content-Type: application/json" -d@formparams.json --url http://test.com
Contents of form params json: it has more than 10 params for simplicity iam including only two
{"params":"{"HOSTS:":"1",date=$date}}
in the above i have added date.
But the date is not replaced. Any help is appreciated.
Use a here document instead of a separate file for the parameters. Inside the here document, you can run the date
command in a command substitution to provide the correct date when the document is read.
curl -O -X POST -H "Content-Type: application/json" -d@- --url http://test.com <<EOF
{"params":"{"HOSTS:":"1", "date": "$(date)"}}
EOF
使用此json传递动态参数
{"params":"{"HOSTS:":"1",date="'$date'"}}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.