I have some code like the following inside a Bash script:
FileNames=""
while read -r FileName; do
...
FileNames+=" -o -iname \"$FileName\""
...
done <"$ListOfFileNames"
FileNames="${FileNames# -o }"
find foo -type f \( $FileNames \)
This was generally working for me until I found that some file names contain spaces (and maybe other special characters). When I added the extra quoting around the use of $FileName
to cover these cases, the expansion of $FileNames
within the find
command starts misbehaving. I have tried various other ways of quoting and escaping and came up empty. I have successfully used variables in many other ways in many other scripts I have written, but this one has baffled me. I am running the script under Cygwin. Is there some nice way to handle this?