我正在尝试运行一个实用程序(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循环中放置相同的实用程序时,是否要继续(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循环下运行。
bash-3.2$vi classInstall.sh
cat $1 | while read theLine
do
$OMNIHOME/bin/nco_confpack -import -server SERVERA -user root -password XXXXX-select Class.list -package Class.jar
done
$ 1只包含两个条目,因此循环,命令只能运行两次
答案 0 :(得分:0)
我不完全确定为什么 while循环通过换行符为您的实用程序提供服务,但您可以通过提供预期的' y'来解决问题。对自己的实用程序:
cat $1 | while read theLine
do
echo y | $OMNIHOME/bin/nco_confpack -import -server SERVERA -user root -password XXXXX-select Class.list -package Class.jar
done