码迷,mamicode.com
首页 > 系统相关 > 详细

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

时间:2016-02-22 10:21:15      阅读:1324      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!