Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm having trouble in making script with interactive login. I have made one but it doesn't ask the login, it automatically log in when i run the script.

i just need the output like this:

please enter ftp server :
username :
password :
share|improve this question

Use read (see help read) - can be like this:

read -p "please enter ftp server : " SERVER
read -p "username : " USERNAM
IFS= read -s -p "password :" USERPSS

In this way, you'll have the server, username and password collected in variables, respectively, $SERVER, $USERNAM and $USERPSS. (Note that because of -s, the password will not be echoed and thanks to IFS=, it can contain space at the beginning.)

Keep in mind that, even though the password is not displayed when prompted, you should not use the $USERPSS variable directly in a command like ftp "${USERNAM}:${USERPSS}@{SERVER}", because it will be revealed to any other user that runs ps (for example) on this computer. Better pass on the password directly as input to the program or (best) just let the program ask for it.

share|improve this answer
look into expect for examples of how to do what @rozcietrzewiacz suggested in the last paragraph. – Tim Kennedy Sep 29 '11 at 11:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.