I'd like to remove a list of files and be asked for confirmation. The list is in the list.txt file. Why the following command doesn't work properly?while read i; do rm -i $i; done < list.txtThe previous command doesn't wait for me but fortunately no file is deleted.I'm using Bash.
Interactively deleting files from a list
bash;shell;io redirection;rm
rm -i reads its answer from standard input, which it inherits from the while loop. So a line of text from list.txt is being used as the answer to the really remove? question. To fix, you'll need to separate the two sources of input. The easiest way is to have read take its input from a separate file descriptor:while IFS= read <&3 -r i; do  rm -i -- $i     # Quote the file name, not just to be safe,                    # but because it's the right syntax.done 3< list.txtYou are no longer redirecting standard input (fd 0) for the while loop, so rm will read from the terminal as desired.Alternatively, you could have done:IFS=$'\n' # set field separator to newlineset -f    # disable globbing upon command substitutionrm -i -- $(cat list.txt)Or, with GNU xargs:xargs -rd '\n' --arg-file=list.txt rm -i --