Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prompt for both user and password in curl command? [duplicate]

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.

like image 349
Dixit Singla Avatar asked Jun 16 '16 07:06

Dixit Singla


1 Answers

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.

like image 182
chiastic-security Avatar answered Oct 05 '22 11:10

chiastic-security