我有一个 bash 脚本,需要使用 curl 将查询发送到 rest api 服务器。
我正在尝试这样做:
$(curl -m100000000000000000000000000000000 -X POST -H "Content-Type: application/json" -d'{"queryType":"SQL", "query": "create table hdfs.bigdata.`databases/'$cleantn'/'$timestamp'` AS (SELECT * FROM dfs.`'$tempfile'`)"}' http://localhost:8047/query.json)
我无法让它工作。* 正在由 bash 进行评估
将其放入变量中仍然不起作用
query='{"queryType":"SQL", "query": "create table hdfs.bigdata.`databases/'$cleantn'/'$timestamp'` AS (SELECT * FROM dfs.`'$tempfile'`)"}'
$(curl -m100000000000000000000000000000000 -X POST -H "Content-Type: application/json" -d''$query'' http://localhost:8047/query.json)
#or
$(curl -m100000000000000000000000000000000 -X POST -H "Content-Type: application/json" -d"$query" http://localhost:8047/query.json)
答案1
query='{"queryType":"SQL", "query": "create table hdfs.bigdata.`databases/'$cleantn'/'$timestamp'` AS (SELECT * FROM dfs.`'$tempfile'`)"}'
交换引号。bash 不会处理语音引号中的任何内容""
或带有转义符的内容\
以上内容变为:
query="{'queryType':'SQL', 'query': 'create table hdfs.bigdata.`databases/'$cleantn'/'$timestamp'` AS (SELECT * FROM dfs.`'$tempfile'`)'}"