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>
答案 0 :(得分:2)
这些字符串也是有效的glob-patterns。因为您没有引用$m
变量,所以您要让shell执行filename expansion。
字符串[10.222.73.99:22]
相当于glob模式[012739.:]
,它将匹配这些字符中的单个字符的文件名,并且看起来您有一个名为{{1}的文件}和当前目录中名为1
的文件。
Always quote your shell variables和don't use for
to iterate the lines of a file
2