如何使用读取命令?



在这方面我是一个完全的初学者,我通常会寻找一个解决方案,而不仅仅是问一个问题,因为我相信有人有类似的问题。但这次我找不到解决问题的方法。
所以我写了一个小shell脚本,使用rclone将文件从可变文件夹复制到我的Google Drive。
我的问题是,我不能输入文件夹名称,如果它包含一个以上的单词。我已经尝试使用read -r folder,但它返回

Command copy needs 2 arguments maximum: you provided 3 non flag arguments: ["One" "Folder/" "Drive:SomeFolder/File"]

如果我使用它返回

Command copy needs 2 arguments maximum: you provided 3 non flag arguments: ["One\" "Folder/" "Drive:SomeFolder/File"]

我希望最后的命令看起来像这样

rclone copy OneFolder/ Drive:SomeFolder/File
#!bin/sh
#upload
echo "Folder Name:"
read -r folder
echo "File Name:"
read -r name
rclone copy ${folder}/ Drive:SomeFolder/${name} 

问题是您调用rclone的方式,而不是您读取变量。您需要引用变量展开。ShellCheck自动检测此问题和其他常见问题。-那个人

最新更新