以下脚本
#!/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] 删除。
我来说两句