如何从bash
包含管道的数组运行命令行?
例如,我想ls | grep x
通过以下方式运行:
$ declare -a pipeline
$ pipeline=(ls)
$ pipeline+=("|")
$ pipeline+=(grep x)
$ "${pipeline[@]}"
但我明白了:
ls: cannot access |: No such file or directory
ls: cannot access grep: No such file or directory
ls: cannot access x: No such file or directory