Below snippet is what I have for determining the path and the filename of where the file is present in the filesystem.
for index in "${!files[@]}"
do
(find . -type f -name "${files[index]}" -print0) 2>&1 | while IFS= read -r -d $'\0' line; do
if [[ ${line} == ${search_pattern}* ]]
then
relative_path=$(echo "$line"|awk '{print substr($0,2)}')
file_path=$(echo "$(pwd)$relative_path" |awk -F/ '{$NF=""; print $0}'|sed -e 's/ /\//g')
file_name=$(echo "$(pwd)$relative_path" |awk -F/ '{print $NF}')
.................................................................
My question is regarding line,
"while IFS= read -r -d $'\0' line; do"
Earlier I was using a for loop over the find command. But there was a post on stackoverflow that this is better and more correct. I tried it, it worked but did not quite understand it. Does this line change the IFS in any way which would change effect the main shell? I tried to figure it out since I am not so well versed in SHELL scripting, I could not get what the line does.
I do not want to deploy this in a production system and then find out that other scripts are failing because IFS variable has been changed.