1

The below loop should read 1 line at a time to the veriable m. But it prints some junk value. Please help.

MyMachine:/u/home/Mohammed_Junaid> cat /tmp/F5
[10.222.73.99:22]
[10.000.73.99:22]
[10.111.73.99:22]
MyMachine:/u/home/Mohammed_Junaid> 
MyMachine:/u/home/Mohammed_Junaid> for m in $(cat /tmp/F5); do echo $m;done
1
2
1
2
1
2
MyMachine:/u/home/Mohammed_Junaid>

1 Answers1

2

Those strings are also valid glob-patterns. Because you're not quoting the $m variable, you're letting the shell perform filename expansion.

It happens that the string [10.222.73.99:22] is equivalent to the glob pattern [012739.:] which will match a filename of a single one of those characters, and it appears that you have a file named 1 and a file named 2 in your current directory.

Always quote your shell variables, and don't use for to iterate the lines of a file

while IFS= read -r m; do echo "$m"; done < /tmp/F5
Community
  • 1
  • 1
glenn jackman
  • 238,783
  • 38
  • 220
  • 352