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?

user3472065
  • 1,259
  • 4
  • 16
  • 32

1 Answers1

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
Inian
  • 80,270
  • 14
  • 142
  • 161