This happens all the time, you are reading from a textfile which has spaces eg:
datainfo 00
datainfo 11
If you do loop on it like this:
for info in `cat $file`; do
echo "info=$info"
done
It will treat datainfo and 00 as two separate lines:
info=datainfo
info=00
Obviously that's not what we want and there are many weird solutions in bash but I'll try and pick what I feel is the simplest and most practical.
My favorite solution:
The key is setting the IFS as below and changing the default delimiter from space " " to newline or \n. You can use the same code and it tells bash to understand not to see a " " space as a delimiter so only a newline is counted. In plain English this makes it so files and directories with spaces are interpreted as intended.
IFS=$(echo -en "\n\b")
for info in `cat $file`; do
echo "info=$info"
done
Solution #2
while read -r; do
line=$REPLY
id=`echo $line|cut -f 2 -d " "`
ip=`echo $line|cut -f 1 -d " "`
done < migratelist.txt
bash, filenames, spaces, textfile, eg, datainfo, info, echo, quot, solutions, ll, simplest, ifs, default, delimiter, newline, counted, directories, interpreted, en, reply, ip, migratelist, txt,