0

I'm writing a document for a curl request.

User should enter email and password, and I need to send user's email and sha1sum of the password via GET method.

If that would be right, the command would look like:

curl 'http://example.com/auth?email={EMAIL}&pwd={SHA1SUM(PASSWORD)}'

I know about printf variable | sha1sum, but how should I use it to concatenate to the quoted string of CURL?

Please not that it should stay a ONE line command.

Mohammad Naji
  • 5,372
  • 10
  • 54
  • 79

1 Answers1

2

You probably want a command substitution using $(). You should use double quotes on the URL in this case (assuming a $PASSWORD variable):

$ curl "http://example.com/auth?email={EMAIL}&pwd=$(echo "$PASSWORD" | sha1sum  | sed -e 's|\w*-$||')"

(Added sed to remove the trailing - from the sha1sum output.)

Will Hogan
  • 909
  • 4
  • 9
  • 1
    You really, really, really should use [proper quoting](http://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-variable) around `$PASSWORD`. – tripleee Nov 11 '15 at 06:59
  • Ha..whoops, that's a bad slip - yes, it most definitely should :) I'd add that it'd be preferable to have built up the string and done some validation / sanitization in the caller and/or some function or script block in the chain. – Will Hogan Nov 11 '15 at 13:24