如何在 shell 脚本中循环执行输入询问实用程序?
How to execute an input asking utility in a loop within a shell script?
我正在尝试 运行 一个实用程序 (nco_confpack),当直接在命令行上使用时它工作得很好。
但是,当我在 shell 脚本的 while 循环中使用相同的实用程序时,该实用程序会进入无限循环而不接受任何输入。
如何避免效用的无限循环?
下面是运行良好的代码片段
bash-3.2$ $OMNIHOME/bin/nco_confpack -import -server SERVERA -user root -password XXXXX-select Class.list -package Class.jar
*********************************************************************
* W A R N I N G *
* *
* This action may overwrite configuration currently in your system. *
* *
* It is recommended that a backup is made of the current data *
* before importing new data. *
* *
*********************************************************************
Do you want to continue (y/n) [N]? y
bash-3.2$
但是,当同一实用程序置于 while 循环中时,Do you want to continue(y/n) 消息进入无限循环而不接受任何输入
bash-3.2$ ./classInstall.sh
Do you want to continue (y/n) [N]? Do you want to continue (y/n) [N]? Do you want to continue (y/n) [N]? Do you want to continue (y/n) [N]? Do you want to continue (y/n) [N]? Do you want to continue (y/n) [N]? Do you want to continue (y/n) [N]? Do you want to continue (y/n) [N]? Do you want to continue (y/n) [N]? Do you want to continue (y/n) [N]? Do you want to continue (y/n) [N]? Do you want to continue (y/n) [N]? Do you want to continue (y/n) [N]? Do you want to continue (y/n) [N]? Do you want to continue (y/n) [N]? Do you want to continue (y/n) [N]? Do you want to continue (y/n) [N]? Do you want to continue (y/n) [N]? ^C
我在这里做错了什么?该实用程序有问题还是我必须在脚本中明确提及某些内容?
该脚本包含相同的命令,只是它在有限的 while 循环下 运行ning。
bash-3.2$vi classInstall.sh
cat | while read theLine
do
$OMNIHOME/bin/nco_confpack -import -server SERVERA -user root -password XXXXX-select Class.list -package Class.jar
done
$1 仅包含两个条目,因此循环,并且该命令预计 运行 仅两次
我不完全确定为什么 while 循环为您的实用程序提供换行符,但您可以通过向实用程序提供预期的 'y' 来解决问题你自己:
cat | while read theLine
do
echo y | $OMNIHOME/bin/nco_confpack -import -server SERVERA -user root -password XXXXX-select Class.list -package Class.jar
done
我正在尝试 运行 一个实用程序 (nco_confpack),当直接在命令行上使用时它工作得很好。 但是,当我在 shell 脚本的 while 循环中使用相同的实用程序时,该实用程序会进入无限循环而不接受任何输入。 如何避免效用的无限循环? 下面是运行良好的代码片段
bash-3.2$ $OMNIHOME/bin/nco_confpack -import -server SERVERA -user root -password XXXXX-select Class.list -package Class.jar
*********************************************************************
* W A R N I N G *
* *
* This action may overwrite configuration currently in your system. *
* *
* It is recommended that a backup is made of the current data *
* before importing new data. *
* *
*********************************************************************
Do you want to continue (y/n) [N]? y
bash-3.2$
但是,当同一实用程序置于 while 循环中时,Do you want to continue(y/n) 消息进入无限循环而不接受任何输入
bash-3.2$ ./classInstall.sh
Do you want to continue (y/n) [N]? Do you want to continue (y/n) [N]? Do you want to continue (y/n) [N]? Do you want to continue (y/n) [N]? Do you want to continue (y/n) [N]? Do you want to continue (y/n) [N]? Do you want to continue (y/n) [N]? Do you want to continue (y/n) [N]? Do you want to continue (y/n) [N]? Do you want to continue (y/n) [N]? Do you want to continue (y/n) [N]? Do you want to continue (y/n) [N]? Do you want to continue (y/n) [N]? Do you want to continue (y/n) [N]? Do you want to continue (y/n) [N]? Do you want to continue (y/n) [N]? Do you want to continue (y/n) [N]? Do you want to continue (y/n) [N]? ^C
我在这里做错了什么?该实用程序有问题还是我必须在脚本中明确提及某些内容?
该脚本包含相同的命令,只是它在有限的 while 循环下 运行ning。
bash-3.2$vi classInstall.sh
cat | while read theLine
do
$OMNIHOME/bin/nco_confpack -import -server SERVERA -user root -password XXXXX-select Class.list -package Class.jar
done
$1 仅包含两个条目,因此循环,并且该命令预计 运行 仅两次
我不完全确定为什么 while 循环为您的实用程序提供换行符,但您可以通过向实用程序提供预期的 'y' 来解决问题你自己:
cat | while read theLine
do
echo y | $OMNIHOME/bin/nco_confpack -import -server SERVERA -user root -password XXXXX-select Class.list -package Class.jar
done