linux shell while读取文件报错解决


linux shell while读取文件报错解决
 
while...do 从文件中读取,报错。
脚本名:while_readFile.sh
脚本内容:
 
Shell代码  
#!/bin/sh  
while read LINE abc  
do  
    echo $LINE  
<strong><span style="color: #0000ff;">done< <(cat ./a.txt)  
</span></strong>  
 注意:两个< 之间有一个空格。
 
执行结果如下:
 
[root@localhost while]# ./while_readFile.sh
./while_readFile.sh: line 5: syntax error near unexpected token `('
./while_readFile.sh: line 5: `done< (cat ./a.txt)'
 
如果使用bash执行的话,就没问题:
 
[root@localhost while]# bash while_readFile.sh
11:22
aa:bbb
:cc
:dd
 
原来是因为 sh 不执行标蓝的用法。
脚本修改如下,以支持sh:
Shell代码  
#!/bin/sh  
while read LINE abc  
do  
    echo $LINE  
done< ./a.txt  

相关内容

    暂无相关文章