我想要写在bash的函数转发参数cp
命令。 例如: 为输入庆典 - 围绕所有数组元素或参数与报价
<function> "path/with whitespace/file1" "path/with whitespace/file2" "target path"
我想它真正做到:
cp "path/with whitespace/file1" "path/with whitespace/file2" "target path"
但是相反,现在我实现:
cp path/with whitespace/file1 path/with whitespace/file2 target path
我尝试的方法到的用途是所有参数存储在数组中,然后只与阵列运行cp命令一起。 像这样:
function func {
argumentsArray=("[email protected]")
cp ${argumentsArray[@]}
}
不幸的是,就像我已经说过了,因此复制失败,则不传输报价。
参见[当环绕shell变量引号?](http://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-外壳变量) – tripleee