I need to write a script that would display all files larger than 1M one by one (in the current dir) and after each file displayed to ask the user whether or not he wants to delete it (Y/n), then if he wants to compress it and finally an option to skip it. After the user chooses an action, the next file should be displayed with the same options offered.
That is what I managed to write so far, but the output gives me the name of the first file (One by one thing works) and gives 'Invalid input' on the following line.
#!/bin/bash
find . -maxdepth 1 -type f -size +1M | while read -r output;
do
echo ${output};
read -r -p "Would you like to delete the file? [Y/n] " input
case $input in
[yY][eE][sS]|[yY])
echo "The file has been deleted!"
;;
[nN][oO]|[nN])
;;
*)
echo "Invalid input..."
exit 1
;;
esac
done
It is clear to me that read -r -p input
does not work in the while loop that already contains read -r output
, but I don't see what I could do in this situation.