The HTTP Authorization request header is sometimes required to authenticate a user agent with a server.
This post explains how to create the header on linux at command line.
The HTTP Authorization request header has the following syntax:
Curl will generate this header for us if we use the
Now for the real question, how do we generate this header for use with curl’s
Here is the first attempt to base64 encode
user:password that is WRONG:
dXNlcjpwYXNzd29yZAo= does not equal
Let’s decode to find the difference:
% is different. What is that?
% symbol is how zsh handles the end of partial lines.
In other words, zsh assumes we want our prompt on a newline even if the last command didn’t end with
a newline. That
% symbol is how we know the difference between a newline the last command output
and a newline zsh graciously inserted for us.
Let’s execute this command under bash and see the difference:
The base64 encoded
user:password that curl generated is not terminated with a newline, unlike the one we generated.
Let’s see if we can get
echo to not add that newline.
-n option for
echo is what we want.
We see that the output is exactly the same as what curl generated.
Putting it all together:
In zsh, a
% symbol is placed at the end of a line where zsh inserted a newline for us.
It is important to include echo’s
-n option when piping content to an encoder to avoid a
newline character being included in the encoded output.