Vla*_*lad 6 bash shell rhel curly-braces expansion
其中一个遗留系统升级到bash4,其大部分脚本停止工作.我已经将它缩小到如何在a中扩展花括号<(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:~]$
Run Code Online (Sandbox Code Playgroud)
之后(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:~]$
Run Code Online (Sandbox Code Playgroud)
它是否为bash4做出了"硬编码"(并且预期?)的更改?或者这个扩展的行为是由一些bash级别的设置(比如set -B/ set +B)控制的,可以切换回old/legacy/bash3模式吗?我宁愿改变一些shell范围的开关(而不是重写一堆脚本).
如果这个(bash3)"功能"在错误修复或改进期间被切断 - 我很惊讶,因为旧的(bash3)语法允许在打字时节省很多...
原始行为是未记录的(并且与包含在进程替换中的代码(如子外壳或类似上下文)的解析方式与其在相同的外部行为中的行为方式相同的一般规则相反)。
因此,这是一个错误,而不是一个功能。此错误已在 bash-4.0-alpha 中修复。引用 CHANGES 条目:
rr。大括号扩展现在允许进程替换不变地通过。
没有可用的运行时标志来恢复此更改。