zoukankan      html  css  js  c++  java
  • shell出现syntax error near unexpected token `<' 解决方法

    最新在看一个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
  • 相关阅读:
    8.22
    webstrom安装流程
    8.21
    8.20
    8.20学习笔记
    使用WebClient异步获取http资源
    导航栏,可直接使用
    asp.net mvc5实现单点登录
    使用C#调用Word的接口生成doc文件与html文件
    下载网页并保存
  • 原文地址:https://www.cnblogs.com/landhu/p/5206136.html
Copyright © 2011-2022 走看看