I am using cURL to GET a page from a website that uses Basic auth. Let say the command line with the credentials looks like this (notice the two dollar signs in "pa$$word"):

curl -u "username:pa$$word" https://example.com

When I stick this command inside a Makefile, I get HTTP/1.1 401 Unauthorised.

The problem is cleary the two dollar signs in combination with the Makefile, because:

curl -u "username" https://example.com

works (provided I type "pa$$word" at the prompt).

And this works in Bash (not inside a Makefile):

   curl -u 'username:pa$$word' https://example.com

I've tried various tricks to escape those dollar signs. So far, I've tried (without success):

   curl -u "username:pa\$\$word" https://example.com
   curl -u "username:pa$$$$word" https://example.com
   curl -u "username:{pa$$word}" https://example.com
   curl ---netrc https://example.com # Credentials are in .netrc

For those downvoters concerned about me putting a password in plain text inside a Makefile - the password in question is for a public test server where the company has disclosed all the credentials required to paricipate in the test on a public webpage.

I basically try to script my test procedure using a Makefile, rather than using ssh to type the same commands over and over again.

2 Answers

2
oguzismail On Best Solutions

$$ in a make file is replaced by $, try following:

curl -u 'username:pa$$$$word' https://example.com

and see Macros section in make specification.

0
jhnc On

Inside double-quotes,the shell needs backslashes to avoid dollar expansion.

Makefiles require doubling of dollars to cause a dollar.

So, to use dollars inside double-quotes in a Makefile, you have to do both:

rule:
        shell-command ... "pa\$$\$$word" ...