I have rm -i inside a for loop but when I run it, it prints the question (“do you want to delete this?) but doesn’t stop to let me answer.
find .. -name "*.tex" | while read line; do
printf "${line%%tex}""aux" | xargs rm -i
done
How do I fix this?
Also I was originally trying to do it by using exec like so
find ..-name "*.tex" -exec printf "${{}%%tex}""aux"\; | xargs rm -i
but I get the error “bad substitution”.
On Linux:
You don’t need to use
xargsif you have a single argument, but you do need to access the original tty somehow while inside the loop. The above works on Linux, there are probably similar tricks on other systems.Another (possibly more portable) way to do this is to “save”
stdinbefore entering the while loop (assuming you’re not using fd 9 for other purposes):Difference between the two: the first one will always try (and possibly fail) to read from the controlling
tty. The other one will read from whateverstdinwas outside the loop.