Home > OS >  Calling service from shell using curl. How to get result and error
Calling service from shell using curl. How to get result and error

Time:02-04

I am calling a service via curl and in case of success I want to get the result in a variable. So I do this call:

result=$(curl -s $URL)

For the success case this works well. In case of an error I get just null in the variable.

In case of error the service throws some http code like 400 and returns some details in the response.

How can I also evaluate the error and fetch the error response?

CodePudding user response:

Stderror to file:

command 2> file

Stderror to stdout:

command > file 2>&1

Try these flags with curl for stderror:

--fail --silent --show-error
  •  Tags:  
  • Related