linux - 如何将 \ 与 read 命令一起使用?
问题描述
我是这个主题的完整初学者,我通常会寻找解决方案,而不是仅仅提出问题,因为我确信有人遇到了类似的问题。但这一次我找不到解决问题的方法。
所以我写了一个小 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 One\Folder/ 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 会自动检测此问题和其他常见问题。——那个人
推荐阅读
- batch-file - 批处理中的两个文件选择器对话框(批处理配方)
- python-3.x - Python @dataclass 无需双重初始化即可继承公共变量
- python - 无法使用标准 gzip Python 库打开 gzip 文件?
- visual-studio-code - 为什么 Visual Studio Code 在我运行它时会显示一个名为“此应用程序无法在您的 PC 上运行”的错误?
- python - 为什么我的 Python 包被安装到这个奇怪的文件夹中?
- python - 在 anaconda 上更新 python
- reactjs - 尝试使用反应挂钩创建获取请求,我的数据仍然为空
- angular - 部署 Angular firebase 项目
- c++ - 具有唯一指针的 C++ std::future 正在同步调用
- python - 带有无效 HTML 代码的 XML 解析错误 (Elementtree)