I think I'm pushing the limits of bash here but I really want to get this done without having to re-write the entire script.
I have something dynamic that is a list of pairs of files which I want to perform operations on. I also want to prompt before I continue with any of the tasks.
It looks like this:
diff -rq $dir1 $dir2 | \
sed -ne 's/^Files \(.*\) and \(.*\) differ$/\1 \2/p' | \
while read differingfilepair; do
...
printf "Continue? (Y/n)"
read -n1 cont
done
As you can see here the while read line
block appears to function as some form of a subshell which receives the content of the data over STDIN.
The $cont
variable basically just slurps the first char of each line of that data (the first char in the path of the first file in the pair of files reported by diff
to be differing), it's not attached to the terminal.
Is there a way to do what I'm trying to do here? I guess a workaround is to use a temporary file but is there another way?
Edit: Using a temporary file later loaded into the while read
block like this: while read l; do ...; done < .tmp_file
still takes over stdin! (though I think this answer will help)