Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run curl from .sh script with defined Content-Type

Tags:

bash

curl

sh

When I'm trying to run test.sh script I've always receive 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 following command from console everything fine:

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

Could you please let me know what is wrong in script, as I understand something is wrong with 'space' escape, but have no idea how to fix it.

Also I've tried following combination, but result the same:

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

UPD:

bash / dash is only available on server. (/bin/sh --> bash)

GNU bash, version 4.2.10(1)-release (x86_64-pc-linux-gnu)
like image 612
kaspian Avatar asked Aug 21 '12 08:08

kaspian


1 Answers

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

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

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

RESPONSE=`$TEST`
echo $RESPONSE
like image 179
Kuf Avatar answered Sep 21 '22 05:09

Kuf