I have a few lines in a shell script whose function is to iterate through directories, match some names, and delete them. Some areas of the file system are write protected and I would like to leave those alone but redirect the error prompt into a log when they are encountered.
Using rm -r /path/to/directory at that point in the script causes the script to output
rm: descend into write-protected directory /path/to/directory/subdirectory?
So it hangs and [eventually] times out when left to its own devices.
I attempted to correct this behavior by piping "n" to that prompt with
yes n | rm -r /path/to/directory
This produces two undesired results:
- Outputting
yes: standard output: Broken pipe; yes: write errorfor every directory that is removed, and - Not returning the
rm: descend into write-protected...message to stdout.
What is the right way to do this?
I realize some other system information might be relevant, but it's probably inferrable from the question.
Aucun commentaire:
Enregistrer un commentaire