Issue
find . -depth -exec stat --format '%n %U %G' {} + | sort -d > acl_file_old
#some days later,do it again,and then compare
find . -depth -exec stat --format '%n %U %G' {} + | sort -d > acl_file_new
while read FILE OWNER GROUP; do
while read FILE_NEW OWNER_NEW GROUP_NEW; do
if [[ $FILE == $FILE_NEW ]]; then
echo "$FILE"
break
done < $result_dir/acl_file_new
done < $result_dir/acl_file_old
Run above bash script,When file name has white space,such as my file here
,while read FILE
works not well.
I already read similar post1,post2,I know looping over find's output is bad practice.The problem is I need save find -exec
result acl_file_old
first.
How to save find -exec
result and used to compare FILE OWNER
,regardless white space file name?
Solution
The read command assigns the words found on the line to the variables.
Note that the last variable is assigned with all the chars remaining up to the end of the line.
The first quick win would be to change the order and make sure that the filename is located at the end with ... -exec stat --format '%U %G %n' {} + ...
Then change the order of the variables to while read -r OWNER GROUP FILE ; do ...
It there are more fancy chars this would be broken anyway. Maybe for
(space) it would do the trick ?
Answered By - Jay jargot Answer Checked By - Robin (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.