JoeSlav
JoeSlav

Reputation: 4815

What output is used in bash (with HTTPie)?

I'm trying to analyze this command:

$ http :"/hello"
HTTP/1.1 401 Unauthorized
<headers>

<body>

I'm trying to save the whole thing in a variable VAR=$( ... ) but to no avail so far.

If I run

$ http :"/hello" 1>/dev/null

everything disappear, so I derive that everything is standard output.

But if I try to send this to a file or to my variable, I don't see the initial portion. So I thought this was stderr, so I did 2>&1 but this doesn't have any effect either.

How can I go about understanding this?

Thanks

Upvotes: 0

Views: 654

Answers (2)

vladmihaisima
vladmihaisima

Reputation: 2248

You could try using option "-v" and "-o" to capture both headers and body in a file, as in:

http -v -o output.file "google.com/bla"

As mentioned by @chepner in the comment, some tools detect if stdout is a file or not and change what they output.

Edit: to work easiest as you wanted (to stdout) you can use:

http -v -o /dev/stdout "google.com/bla"

Upvotes: 0

chepner
chepner

Reputation: 532208

HTTPie alters its output, depending on whether it is writing to the terminal or a regular file.

From the manual

Redirected output

HTTPie uses a different set of defaults for redirected output than for terminal output. The differences being:

Formatting and colors aren’t applied (unless --pretty is specified). Only the response body is printed (unless one of the output options is set). Also, binary data isn’t suppressed.

[...]

There are specific command line options you can use to override the defaults.

Upvotes: 1

Related Questions