【发布时间】:2019-12-24 21:26:45
【问题描述】:
问题
我的代码首先遍历一个文件,每行都有一个文件夹路径,确保它们是正确的(它确实通过了,我也知道这些是有效路径),然后尝试将它传递给程序 @987654322 @ 但错误。
问题似乎完全取决于我如何创建或使用folderList(您可以将其视为第一个回声),但我不确定如何解决。
输入
/media/sf_D_DRIVE/VirtualMachines Backups/
/media/sf_C_DRIVE/Websites/47/sln/site/App_Data/
错误输出
"/media/sf_D_DRIVE/VirtualMachines Backups/" "/media/sf_C_DRIVE/Websites/47/sln/site/App_Data/"
"/media/sf_D_DRIVE/VirtualMachines: [Errno 2] No such file or directory: '"/media/sf_D_DRIVE/VirtualMachines'
Backups/": [Errno 2] No such file or directory: 'Backups/"'
"/media/sf_C_DRIVE/Websites/47/sln/site/App_Data/": [Errno 2] No such file or directory: '"/media/sf_C_DRIVE/Websites/47/sln/site/App_Data/"'
代码
#this snippet reads in folder paths from a file
while read line
do
exists=false
if [ -f "$line" ]; then
exists=true
fi
if [ -d "$line" ]; then
exists=true
fi
if [ $exists = false ]; then
exit 1
fi
folderList+=" $line"
done < "$2"
echo $folderList #gets past here successfully
borg create -s --progress $1::${dateString} $folderList
【问题讨论】:
-
使用数组构建多个带空格的参数:bash - surround all array elements or arguments with quotes
标签: bash shell whitespace quotes