【发布时间】:2016-03-08 13:27:20
【问题描述】:
我想在 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=( "$@" )
cp ${argumentsArray[@]}
}
不幸的是,它并没有像我已经提到的那样转移引号,因此复制失败。
【问题讨论】: