Unix FOR loop not working with IP addressees

时间:2015-12-10 01:58:18

标签: shell loops unix for-loop

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 个答案:

答案 0 :(得分:2)

这些字符串也是有效的glob-patterns。因为您没有引用$m变量,所以您要让shell执行filename expansion

字符串[10.222.73.99:22]相当于glob模式[012739.:],它将匹配这些字符中的单个字符的文件名,并且看起来您有一个名为{{1}的文件}和当前目录中名为1的文件。

Always quote your shell variablesdon't use for to iterate the lines of a file

2
相关问题