Answer a question

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.

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.

Logo

Ubuntu 社区为您提供最前沿的新闻资讯和知识内容

更多推荐