I cannot figure out how to solve this problem. I got a function, and I send to it a directory and a word. I want to search all files in that directory which contain that word, but if I can not read them, I want to print my own error. Here is what I have:
find $1 -type f -print0 | xargs -0 grep "$2" || error 3 "You can not read the archive."
Where:
- $1 -> Directory
- $2 -> Word to search.
It works, but the point is that I got the grep error if I find a non-readable file, and I dont want it to appear. Do you know what can I do in order to solve this?
Thank you in advance.
EDIT: Ok and if I use this:
result=$(find $1 -type f -print0 | xargs -0 grep -s "$2" || error 3 "You can not read the archive.")
It only saves the error once, how can I do it if I want to print the error once for every archive?