Reputation: 1015
I am writing a shell script in which I need to work on the response of an api. I called the api using curl command and trying to get its response in shell so that I can loop over response and print it. But I am not able to get the response. Here is the script:
#!/bin/bash
result=$(curl "https://example.com/test")
echo "test"
RESP=`echo $result | grep -oP "^[^a-zA-Z0-9]"`
echo "$RESP"
I am getting empty response after test. Can somebody help me over this ?
Upvotes: 0
Views: 16318
Reputation: 121
Try this syntax:
#!/bin/bash
result="$(curl -s 'https://example.com/test')"
echo "result: '$result'"
RESP=$(echo "$result" | grep -oP "^[^a-zA-Z0-9]")
echo "RESP:'$RESP'"
Explanation:
Upvotes: 3