I am on ubuntu 11.10 using bash scripts
I want to remove all files matching a string pattern and I am using the following code
find . -name "*$pattern*" -exec rm -f {} \;
I have encountered a problem when $pattern is empty. In this case all my files in my current directory were deleted. This was not intended. If no pattern is passed, I definitely do not want to delete all my files.
What would be a safe way to tackle file deletion?