2

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.

Note: Some has suggested that this is a duplicate of a more general question about Escaping in makefile. However, my question is specifically about how to escape 2 dollar signs inside a Makefile. It is not obvious (at least not to me) how the general case answer applies to this use case.

tripleee
  • 175,061
  • 34
  • 275
  • 318
Free Radical
  • 2,052
  • 1
  • 21
  • 35
  • 2
    Have you tried single quotes? – randomuser5215 Apr 21 '19 at 13:37
  • `curl -u 'username:pa$$word' https://example.com` works fine here – oguz ismail Apr 21 '19 at 13:38
  • @oguzismail - I know, but but the problem is related to Makefile, not to bash alone (see edited question). – Free Radical Apr 21 '19 at 13:40
  • What is the `SHELL` variable in the makefile? – randomuser5215 Apr 21 '19 at 13:42
  • 1
    Seems to be a very bad idea to store a password in plain text. Use SSH or like that. – aparpara Apr 21 '19 at 13:43
  • Can you give the output when you add `echo "$$"` in the build configuration? – randomuser5215 Apr 21 '19 at 13:45
  • @aparpara That's totally irrelevant to this question. I *know* that one should not store password in plain text - but this password is to a test server where the company that put it on the web posted the credentials on the test server home page. – Free Radical Apr 21 '19 at 13:52
  • @FreeRadical, if you know it, why you write it in the title? May be my remark is irrelevant to the question itself, but it is relevant to the downvotes it received. – aparpara Apr 21 '19 at 14:01
  • @aparpara Ok, I've added context about where that password came from – hoping to avoid getting more downvotes. – Free Radical Apr 21 '19 at 14:08
  • @tripleee The accepted answer is a shorter and more direct answer to my question than the one you link to. It only addresses a single $. – Free Radical Sep 24 '21 at 05:20
  • But the principle is the same; we don't really need two separate questions about how to escape dollar signs and it should be obvious how to escape two if you know how to escape one. The duplicate will still be here if somebody has precisely this question. – tripleee Sep 24 '21 at 05:38

2 Answers2

2

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

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

and see Macros section in make specification.

oguz ismail
  • 1
  • 16
  • 47
  • 69
2

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" ...
jhnc
  • 11,310
  • 1
  • 9
  • 26
  • I had a similar issue, where I wanted to pass `"$(inherited) -Wall"` to `xcodebuild` from a Makefile (with neither the Makefile nor the shell substituting anything, so Xcode gets a chance to substitute it) and this was exactly what was needed, thank you! – uliwitness Oct 05 '22 at 12:41