首页 > 系统服务 > 详细

shell出现syntax error near unexpected token `<' 解决方法

时间:2016-02-22 10:21:12      阅读:252      评论:0      收藏:0      [点我收藏+]

最新在看一个shell资料时,按照教材,却出现如下错误,不能运行

如下,简单的脚本:

#!/bin/bash
cat |while read line
do
  echo $line
done < <(data.txt|awk {print $0})

运行时,却出现如下错误

[root@localhost shellcookbook]# sh while_test.sh 
while_test.sh: line 5: syntax error near unexpected token `<while_test.sh: line 5: `done < <(data.txt|awk {print $0})

然后在单行运行时,却没有错误

[root@localhost shellcookbook]# while read line;do echo $line;done < <(cat data.txt|awk {print $1})
1
2
3
4

 

在网上查看后,确认无脚步错误,无dos文件错误。还是没有好的解决方法。通过多方求证。原来是bash 3.0后,shell中加入了新的符号"<<<" 可以获取子任务

现将脚本更改如下,成功运行:

#!/bin/bash
cat |while read line
do
  echo $line
done <<< `cat data.txt|awk {print $0}`

成功运行

[root@localhost shellcookbook]# sh while_test.sh 
1 2 3 4

 

shell出现syntax error near unexpected token `<' 解决方法

原文:http://www.cnblogs.com/landhu/p/5206136.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!