Run curl from .sh script with specific content type

When I try to run test.sh script, I always get an error from curl:

curl: (6) Couldn't resolve host 'application'

test.sh:

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

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

RESPONSE=`$TEST`
echo $RESPONSE

But if I just run the following command from the console, everything is fine:

curl http://127.0.0.1 -H Content-Type:\ application/json

Could you tell me what is wrong in the script, since I understand that something is wrong with the escape of "space", but has no idea how to fix it.

I also tried the following combination, but the result is the same:

CT="Content-Type: application/json"
TEST="curl http://127.0.0.1 -H \"$CT\""

UPD:

bash / dash is only available on the server. (/ bin / sh → bash)

GNU bash, version 4.2.10(1)-release (x86_64-pc-linux-gnu)
+5
source share
2 answers

Run the following: (remove the space after the Content-Type)

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

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

RESPONSE=`$TEST`
echo $RESPONSE
+7
source

You can try: bash -c your_bash_file.shIt worked for me with the same problem

+1
source

All Articles