最新在看一个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 : syntax error near unexpected token `<'
while_test.sh: line : `done < <(data.txt|awk '{print $0}')'

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

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

在网上查看后,确认无脚步错误,无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
   

shell出现syntax error near unexpected token `<' 解决方法的更多相关文章

  1. 解决shell脚本“syntax error near unexpected token `fi'”的问题。

    执行shell脚本的时候,提示如下错误: 查询资料后发现: 执行: vi finddir.sh 然后,输入 :set ff 结果是: 解决方案就是,修改为unix: :set ff=unix 执行保存 ...

  2. 写shell,运行出错:syntax error near unexpected token `$’do\r”

    cygwin下面写shell,运行出错:syntax error near unexpected token `$’do\r” 写shell,运行出错:syntax error near unexpe ...

  3. shell编程报错:“syntax error near unexpected token `”

    今天写了个shell脚本,在自己机器上运行正常,给同事,运行报错syntax error near unexpected token `,左看右看shell脚本没有问题,没有办法google搜索,发现 ...

  4. Shell脚本报错--syntax error near unexpected token for((i=0;i<$length;i++))

    现象: shell脚本使用Nodepad++进行本地编辑,在编辑后上传到linux机器进行执行时提示“syntax error near unexpected token for((i=0;i< ...

  5. syntax error near unexpected token `then'问题的解决

    #!/bin/bash #if program test echo 'a:' read a if  [  "$a"  =  "English"  ];then ...

  6. 执行shell脚本提示“syntax error near unexpected token for((i=0;i&lt;$length;i++))”

    sh脚本例如以下: #!/usr/bin/env bash county="3 4 5 6 7 8 9 10 11 12 16 29 39 44 53 62 72 84 97 115 128 ...

  7. syntax error near unexpected token `do(写的shell脚本出现格式问题)--->1.问题2.展示信息3.解决方案

    1问题:Linux和windows下的回车换行符不兼容的问题 [root@node-01 script]# sh start_zk.sh art_zk.sh: line 3: syntax error ...

  8. 解决执行脚本报syntax error: unexpected end of file或syntax error near unexpected token `fi'错误的问题

    参考:https://blog.csdn.net/u012453843/article/details/69803244 解决执行脚本报syntax error: unexpected end of ...

  9. syntax error near unexpected token `then'问题的解决

    http://blog.csdn.net/gongmin856/article/details/7690917 #!/bin/bash #if program test echo 'a:' read ...

随机推荐

  1. php-config 介绍

    php-config php-config 是一个简单的命令行脚本用于获取所安装的 PHP 配置的信息. 在编译扩展时,如果安装有多个 PHP 版本,可以在配置时用 --with-php-config ...

  2. openfire User Service 和删除分组的方法

    z4PstKlN 服务器-> 系统属性 plugin.userservice.enabled 值为 true 增加用户 9090/plugins/userService/userservice? ...

  3. tensorflow 单机多GPU mnist实例

    http://blog.csdn.net/guotong1988/article/details/74748806 如何使用多GPU http://wiki.jikexueyuan.com/proje ...

  4. C++ 数据抽象

    C++ 数据抽象数据抽象是指,只向外界提供关键信息,并隐藏其后台的实现细节,即只表现必要的信息而不呈现细节. 数据抽象是一种依赖于接口和实现分离的编程(设计)技术. 让我们举一个现实生活中的真实例子, ...

  5. 多媒体开发之h264中的sps---sps信息提取之分辨率宽高提取2

    -------------------author:pkf -----------------------------time:2015-8-20 -------------------------- ...

  6. 在windows下编译ffmpeg

    编译ffmpeg,我在网上找了很多相关的方法,但最后都没编译成功. 所以下面就记录下自己的编译方法吧,留着以后编译的时候做参考. 1.首先,下载编译工具MinGW+Msys,搭建编译环境.工具下载地址 ...

  7. 转载:【原译】Erlang常见注意事项(Efficiency Guide)

    转自:http://www.cnblogs.com/futuredo/archive/2012/10/17/2726416.html Common Caveats(常见注意事项) Erlang/OTP ...

  8. 性能测试指标的理解--cpu和load

    第一次做性能测试,按照操作文档磕磕碰碰的完成了,并且拿到了结果,看到一堆的指标和数据,还是傻眼了,不知道各个指标是什么意思了. 咨询了大牛和度娘,消化理解了一下,不知道是不是正确的. CPU使用率: ...

  9. Linux 快速删除大量小文件方法

    进行以下两步操作即可: 1.第一步:创建空的文件夹: mkdir  /tmp/blank 2.第二步:执行以下命令:rsync --delete-before -d /tmp/blank/ /home ...

  10. MathType在字母上加虚线的方法

    在数学中根据不同的需要,会对其中的公式或变量字母作不同的标记.这些标记在用MathType编辑数学公式时同样也要准确地编辑出来,例如在字母上方加虚线.这种数学样式在使用时也是根据自己的数学问题来使用的 ...