I have a script that asks some questions to the user and repeats the question until the user has answered something appropiate. This is done with an infinite loop that is break
'd when an acceptable answer is read:
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
This is working fine when called independently. The problem is when I execute this script inside a | while read ...
loop:
# 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
The ouptut of the grep
command alone is what should be in my case:
15-gitcredentials
20-workspace
40-download_latest_dev_vapp
99-change_username_and_password
Problem:
the 15-gitcredentials
script (the first snip I posted is part of this script) is reading the same STDIN
that the | while read execScript
part is expected to read, i.e. the output of the grep command. How could I made the 15-gitcredentials
script to read not from STDIN
but from other descriptor?
You are approaching the problem with the wrong solution.