我有一个脚本,向用户提出一些问题,并重复问题,直到用户回答某个问题。 当一个可接受的答案被读取时,这是通过一个无限循环来完成的:
while true do read -p "Which helper do you prefer (cache, store)? " HELPER if [ "$HELPER" = "store" -o "$HELPER" = "cache" ] then break else error "Invalid option. Choose again" fi done
独立调用时工作正常。 问题是当我在一个| while read ...执行这个脚本 | while read ...循环:
# find scripts that should be run as non-root user, and run them all sequentially grep -l '^\s*require_non_root' [0-9]* | while read execScript do echo "=== EXECUTING $execScript ===" "./$execScript" done
grep命令的单独是我的情况应该是这样的:
15-gitcredentials 20-workspace 40-download_latest_dev_vapp 99-change_username_and_password
15-gitcredentials脚本(我发布的第一个15-gitcredentials是这个脚本的一部分)正在读取相同的STDIN , | while read execScript部分则需要读取,即grep命令的输出。 我怎么能使15-gitcredentials脚本不从STDIN而是从其他描述符中读取?
您正在用错误的解决scheme来解决问题。
for p in $(grep -l regex files); do echo -n "Executing $p ... " ./$p echo "[DONE]" done