【问题标题】:Insert data in bash prompt with script [duplicate]使用脚本在 bash 提示符中插入数据 [重复]
【发布时间】:2017-04-19 21:45:32
【问题描述】:

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

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

有什么建议吗?

【问题讨论】:

    标签: bash console


    【解决方案1】:

    更改您的 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
    

    【讨论】:

    • 所以,在命令“kinit $username”之后,当我需要输入密码时,我使用命令 => read -s -p "Enter password: " password ???
    • 不起作用 :( 控制台仍然卡在“输入用户密码......”
    • @user3472065:您要么 1) 没有按照我的建议使用代码 2) 要么您没有发布完整的脚本。我没有字符串Enter password for user,您的脚本中还有其他read 命令吗?
    • 我解决了这个问题:echo $password | kinit $用户名
    • 感谢支持!!!
    猜你喜欢
    • 1970-01-01
    • 2015-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-24
    • 1970-01-01
    • 2019-03-30
    • 2013-03-23
    相关资源
    最近更新 更多