script sh : command wait an input from keyboard, but script type the input

我有一个需要从键盘输入的命令,不能直接从命令行获得它,就像sudo一样,我忘记了将一个已知变量传递给终端输入的语法:[sudo] password for cl-r:'

#/bin/bash (or ksh)
.....
VARIABLE_NEEDED=$1
mycommand_wait_and_needs_input_from_keyboard [?? magic-instruction_beginning ??] # command prompt for input
VARIABLE_NEEDED
[?? magic-instruction_end ??]
# ... command executed
[ $? != 0 ] && ...

也许你的意思是:

echo -n "$VARIABLE_NEEDED" | mycommand_wait_and_needs_input_from_keyboard

Take a look at line 7 of my dotfiles. You can invoke sudo -v in a bash script to run it with sudo permissions.

链接地址: http://www.djcxy.com/p/25558.html

上一篇: 通过键(如ENTER或ESC)在bash中创建中断

下一篇: 脚本sh:命令等待来自键盘的输入,但脚本输入输入