Instead of:
IFS=$'\n'
for i in `cat "$1"`; do
echo "$i" >> xtempfile.tmp;
done
You can do something like:
while IFS=$'\n' read -r line; do
echo "$line"
done < "$1" >> xtempfile.tmp
This would set the IFS
variable for the duration of while loop
.
*Addition based on samveen's comments. Anytime a change is made to IFS
in a subshell, the changes are reverted automatically. However, that is not true when you made modifications in interactive shell. The above suggestion is the required handling done to ensure we don't accidentally modify the IFS
for the entire shell. *