What I want to do and what is happening: I want to run a CURL request within my (first) shell script which is currently only working if I hardcode everything.
As soon as I'm using variables, the target responds with an error message.
The respective lines:
This works:
curl -X GET 'https://[the target]' [some headers] -d '{"strObjectType": "ABC","strSearchPattern": "DEF*"}' -k
This works not:
curl -X GET 'https://[the target]' [some headers] -d '{"strObjectType": "${OBJTYPE}","strSearchPattern": "${SEARCH}"}' -k
The command which is used to execute the script:
./abc.sh ABC DEF*
Here the complete script:
#!/bin/sh
#Getting Input
if [ -z "$1" ]; then
echo "Please supply an object type as first parameter!"
exit 1
fi
OBJTYPE="$1"
if [ -z "$2" ]; then
echo "Please supply a search string as second parameter!"
exit 1
fi
SEARCH="$2"
echo "+++Executing HTTP-REST-Request+++"
#--------------DEBUGGING SECTION START
echo "+++Parameter+++"
echo "Object Type: \"${OBJTYPE}\""
echo "Search Parameter: \"${SEARCH}\""
echo "curl -X GET 'https://[the target]' [some headers] -d '{\"strObjectType\": \"${OBJTYPE}\",\"strSearchPattern\": \"${SEARCH}\"}' -k"
#--------------DEBUGGING SECTION END
echo "+++Result+++"
#Executing HTTP-REST-Request to get Physical Host Data
#curl -X GET '[the target]' [some headers] -d '{"strObjectType": "ABC","strSearchPattern": "DEF*"}' -k
curl -X GET '[the target]' [some headers] -d '{"strObjectType": "${OBJTYPE}","strSearchPattern": "${SEARCH}"}' -k
echo "+++Execution Successful+++"
The output from the target:
Cannot read property '0' of undefined
The content of the two lines must be different in any way. Does anybody know what the problem is?