7

I am doing a post call to MarkLogic server using CURL command in Ubuntu.

In the command if I'll write like

--user username

It will prompt for password.

Is there any way to prompt for both username and password?

Basically I don't want to hard code the username and password because in my case username and password will change very frequently So I want user to enter the username and password.

Dixit Singla
  • 293
  • 2
  • 6
  • 16

1 Answers1

12

You'd have to do this in two steps: first read in the username, then use it in your curl command. So in bash it would come out something like this:

read -p "Username: " CURLUSER
curl --user "${CURLUSER}" ...

If you wanted to, you could wrap this up in a little script, along these lines:

#!/bin/bash
read -p "Username: " CURLUSER
curl --user "${CURLUSER}" "$@"

Now save that as curl-with-user.sh, make it executable, and you can use it as a replacement for curl, but one that will start by asking you for the username.

The point of the "$@" is to ensure that any arguments you pass to your script also get passed to curl.

Leistungsabfall
  • 6,368
  • 7
  • 33
  • 41
chiastic-security
  • 20,430
  • 4
  • 39
  • 67