我有这个示例代码:
find "$1" ! -regex "$regex" 2>/dev/null | while read line ; do
a="$line"
done
echo ("$a") # prints nothing because of subshell
我需要:
- subshell 使
$a
外部可见(在全局范围内)的解决方法 - 不使用 bash 的进程替换
- 兼容 dash、bash 和 korn shell
我怎样才能做到这一点?有没有简单的解决方案?