I need to make a
bash script that takes two arguments, one is the string to search for in the filenames and the next one is the file path to search in. Next it needs to go through one matching file at a time and print it out, then prompt the user if they want to delete it or not.
An example of it would be:
./scriptName.sh foo /path/to/directory/ /path/to/directory/foo.txt Delete this? (y/n) user input /path/to/directory/foop.txt Delete this? (y/n) user input etc...
I originally tried
find $2 -type f -name "*$1*" -print
find $2 -type f -name "*$1*" -delete
$1 is the first argument and
$2 are the second argument of the script.
This worked until I realized that it had to list each found file separately and prompt to delete them which is a bit of problem since the previous two lines of code just deletes all the matching files at once.