其中一个旧系统已升级到bash4,大部分脚本都无法工作。我已将其缩小为如何在 <(cmdA ...|cmdB ... file{1,2}|cmdZ ...)
内展开花括号。
为了更好地说明区别:
之前 (bash 3.2.25):
[root@host1:~]$ bash -version|head -1
GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)
[root@host1:~]$ cat <(echo sort file{1,2})
sort file1
sort file2
[root@host1:~]$ join <(sed 's/\r//g;s/^[^:]*://' file{1,2}|LANG=C sort)
[root@host1:~]$
在bash 4.1.2之后:
[root@host2:~]$ bash --version|head -1
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
[root@host2:~]$ cat <(echo sort file{1,2})
sort file1 file2
[root@host2:~]$ join <(sed 's/\r//g;s/^[^:]*://' file{1,2}|LANG=C sort)
join: missing operand after `/dev/fd/63'
Try `join --help' for more information.
[root@host2:~]$
这是一个为bash4硬编码的(并且是预期的)更改吗?还是这种扩展的行为由一些bash级别的设置控制(比如
set -B
/set +B
),可以切换回旧版/遗留版/bash3模式?我宁愿更改一些整个shell的开关(而不是必须重写一堆脚本)。如果这个(bash3)“特性”在bug修复或改进过程中被削减了,我感到惊讶,因为旧的(bash3)语法允许节省大量打字...
sed
的两个参数?我不知道这是否符合正确的、有文档支持的行为……也就是说,据我所知,你的代码依赖于一个错误。 - Charles Duffy<(cmd {a,b})
扩展为两个<(cmd a) <(cmd b)
并传递给join等。这些脚本广泛使用此功能,将其嵌套到多个级别和脚本中进行测试(不想用我的粗手指触摸它并生成新错误)。 - Vlad<(...)
内部的命令被解析为与任何其他命令相同,因此<(cmd {a,b})
应等同于<(cmd a b)
。 - Barmar