使用已定义的Content-Type从.sh脚本运行curl

kas*_*ian 8 bash curl sh

当我尝试运行test.sh脚本时,我总是收到curl的错误:

curl: (6) Couldn't resolve host 'application'
Run Code Online (Sandbox Code Playgroud)

test.sh:

#!/bin/sh
CT="Content-Type:\ application/json"

TEST="curl http://127.0.0.1 -H $CT"
echo $TEST

RESPONSE=`$TEST`
echo $RESPONSE
Run Code Online (Sandbox Code Playgroud)

但是,如果我只是从控制台运行以下命令一切正常:

curl http://127.0.0.1 -H Content-Type:\ application/json
Run Code Online (Sandbox Code Playgroud)

你能不能让我知道剧本中有什么问题,因为我知道'太空'逃脱有些问题,但不知道如何修复它.

我也试过以下组合,但结果相同:

CT="Content-Type: application/json"
TEST="curl http://127.0.0.1 -H \"$CT\""
Run Code Online (Sandbox Code Playgroud)

UPD:

bash/dash仅在服务器上可用.(/ bin/sh - > bash)

GNU bash, version 4.2.10(1)-release (x86_64-pc-linux-gnu)
Run Code Online (Sandbox Code Playgroud)

Kuf*_*Kuf 17

运行以下命令:(删除Content-Type后的空格)

#!/bin/bash
CT="Content-Type:application/json"

TEST="curl http://127.0.0.1 -H $CT"
echo $TEST

RESPONSE=`$TEST`
echo $RESPONSE
Run Code Online (Sandbox Code Playgroud)