bash中的命令无法使用绝对路径

486

以下脚本

#!/bin/bash
command="cp -f '/Input Folder/test.txt' '/Output Folder/test.txt'"
echo "["$command"]"
$command

给出以下输出:

[cp -f '/Input Folder/test.txt' '/Output Folder/test.txt']
cp: target ‘Folder/test.txt'’ is not a directory

而命令

cp -f '/Input Folder/test.txt' '/Output Folder/test.txt'

工作完美。

我应该如何正确环绕路径?bash是否暗示对'或'符号进行某种特殊处理?

控制台盒

请改用数组。另外,command是内置名称。最好使用另一个变量,以防万一。

cmd=(cp -f '/Input Folder/test.txt' '/Output Folder/test.txt')
echo "[${cmd[*]}]"
"${cmd[@]}"

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章