I have a find result saved in a variable and I am protecting the spaces in filenames by adding a single quotes around the output. So the for loop works flawlessly.
My problem is when I intend to grep one of those files, it says "File does not exist" because is literally taking the single quotes as part of the filename.
How can I overcome this??
all_files=$(find . -type f -printf "'%p'")
for file in $all_files
do
grep 'hello' $file ### this says "file.not found because of the single quotes
done
%p
. 2) It is better to double quote the entire declaration of the variable like this:"$(find . -type f -printf "'%p")"
find
results to a string - for a robust solution see Loop through find command results that have been added to an array? filenames with gaps treats as 2 entries – steeldriver Mar 24 '19 at 03:04