1
我似乎无法弄清楚如何让此循环暂停以供用户选择。它每次都会自动选择*
选择。我究竟做错了什么?如何暂停循环以允许用户选择变量
#!/bin/bash
while read -r lineIn; do
if [[ "$(cmd_output)" != "" ]]; then
echo "choose one letter (a)(b)(c)(d)(e)"
read abcde
case $abcde in
[aA]) do stuff and continue the loop;;
[bB]) do stuff and do not continue the loop;;
[cC]) do other stuff and continue the loop
[dD]) do nothing and continue the loop;;
[eE]) exit;;
*) echo "Danger Will Robinson!";;
esac
else
echo "No output from command!"
fi
done < filename
1.你真的想要/需要'read -p'吗?我认为只是'读abcde'应该可以工作。 2.构造像'[a | A]'“煮沸”到'[aA |]',所以我觉得你真的只需要'[Aa]'(等等)。否则,看起来不错。祝你好运! – shellter
我添加'-p'选项的原因是因为我原本以为它会暂停以提示用户输入。但你是对的,这是没有必要的。对于'ksh', –
,'read'手册页显示'-p'是“从当前协同进程读取而不是标准输入。文件结束导致读取断开协处理,从而另一个可以是创建“,但它可能与”bash“不同(太累了,现在看起来不太合适)。祝你好运。 – shellter