shell(26) : curl json传递变量

#!/bin/sh
current=`date "+%Y-%m-%d %H:%M:%S"`  
timeStamp=`date -d "$current" +%s`   
#将current转换为时间戳,精确到毫秒  
currentTimeStamp=$((timeStamp*1000+`date "+%N"`/1000000)) 
echo "$current $i $currentTimeStamp"

param1='[{"k1":"v1","k2":"v2","timestamp":'
param2=',"k3":"v3","k4":3.0}]'
paramall="$param1 $currentTimeStamp $param2"
echo $paramall

curl -H "Content-Type:application/json" -X POST -d "$paramall" 'http://www.baidu.com'
  1. 定义json需要用单引号包住
  2. curl传入json变量需要用双引号包住
  3. 两个单引号之间的字符串是不可变的

你可能感兴趣的:(shell,json,curll,json变量,curl传递变量)