John Kugelmanβs answer is correct and concise, and you must accept it. I am addressing your syntax question here for completeness only.
You cannot use ${read line} to do read - the binding syntax actually means (vaguely) that you want the value of a variable whose name contains a space. You may have fired for $(read line) , but in fact, the correct way to write a until loop will be longer in lines
grep "regex" "filepath" | until read line; [[ -z "$line" ]]; do
... but, of course, when there is no way out, the pipeline will not receive lines, so while and until are wrong here.
It is worth emphasizing that the reason you need a separate do is because you can have several commands there. Even something like
while output=$(grep "regex filepath"); echo "grep done, please wait ..."; count=$(echo "$output" | wc -l); [[ $count -gt 0 ]] do ...
although again, this is much more mysterious than you will ever need. (And in this particular case, you'd probably want to actually want an if rather than a while .)
As noted earlier, there is no reason to use a cycle like this, but I wanted to understand the question of how to write such a cycle when you really want it.
source share