【问题标题】:Command errors when run with #!/bin/sh [duplicate]使用 #!/bin/sh 运行时出现命令错误 [重复]
【发布时间】:2016-10-27 23:52:25
【问题描述】:

shell 脚本中的命令:

mapfile -t my_array < <( grep '$(ABC)' ${file} |awk -F_ '{print $2}')

使用#!/bin/sh 运行时失败。

error: syntax error near unexpected token `<'

同样的命令适用于#!/bin/bash

【问题讨论】:

  • 嗯,Bash 和 sh 是不同的东西。 Bash 支持一些 sh ​​不支持的东西。你期待什么?!
  • 另外,您似乎忘记在问题中包含问题。

标签: bash sh


【解决方案1】:

进程替换不是 POSIX sh 中存在的功能;它是 bash 和 zsh 也采用的 ksh 扩展。

使用#!/bin/sh 只能保证存在 POSIX sh 规范中给出的功能。

【讨论】:

    猜你喜欢
    • 2013-08-12
    • 2021-12-09
    • 2019-11-13
    • 2019-12-06
    • 2019-09-08
    • 2012-03-15
    • 1970-01-01
    • 2021-01-08
    • 2016-05-17
    相关资源
    最近更新 更多