用脚本插入bash提示中的数据



我创建了一个bash脚本,该脚本在循环中执行一些操作。在一个命令中,控制台要求输入,我不知道如何提供此输入以继续我的脚本。

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

任何建议?

更改您的 main while-loop,从与stdin不同的文件描述符中读取,并使用readstdin读取并使用-s来抑制文本从控制台中显示出来。

while read -u 3 line; do
    # Your rest of the code 
    read -s -p "Enter password: " password
done 3<myfile

最新更新