0

I created a bash script that perform some operations inside a while loop. In one command, the console asks for an input and I have no idea how to provide this input in order to continue with my script.

while read line;
do
    string_array=($line)
    username=${string_array[0]}
    password=${string_array[1]}
    kinit $username
        ===> here I need to enter the $password and press "ENTER" to continue

done <myfile

Any suggestion?

0

1 Answer 1

1

Change your main while-loop to read from a different file descriptor than stdin and use read to read from stdin and use -s to suppress text from showing up in console.

while read -u 3 line; do
    # Your rest of the code 
    read -s -p "Enter password: " password
done 3<myfile
Sign up to request clarification or add additional context in comments.

5 Comments

So, after the command "kinit $username", when I need to enter password, I use the command => read -s -p "Enter password: " password ???
does not work :( the console is still stuck at "Enter password for user...."
@user3472065: You are either 1) not using the code as I suggested 2) or you have not posted the complete script. I did not have a string Enter password for user, do you have other read commands in your script?
I solved the issue doing that: echo $password | kinit $username
Thanks anyway for the support!!!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.