bash - 带有 bash 脚本的自定义文件复制器
问题描述
我编写了这些代码行来将用户提供的文件复制到目录中......但是条件部分不断提出错误......
这是代码:
echo Enter filename to copy:
read files
echo
echo Enter Directory to copy files to:
read dir
echo
echo copying file $files to $dir directory
#check if file exists
if [ ! -e "$files" ] then
echo file does not exist
exit 0
else
if [ ! -d "$dir" ]; then #check if dir exists
mkdir ~$dir
echo ~$dir
cp $files $dir
ls $dir
fi
fi
预期行为:作为 argv 提供的文件应复制到提供的目录,如果该目录不存在,则应创建它。如果文件不存在,则退出脚本并显示文件不存在的消息。
实际行为:syntax error near unexpected token 'else'
解决方案
您;
在第一if
条语句中缺少 a 。它应该是:
if [ ! -e "$files" ]; then
推荐阅读
- python - discord.py 'NoneType' 对象没有属性 'find'
- python - 在 Django 中更新表单时如何更改状态?
- c - 正确使用 ifdef 进行自定义调试
- c - 谁能帮我理解这个汇编语言代码?
- api - 为什么我的函数没有向 App Display 返回任何内容?
- java - Apache Flink 流限制
- awk - 使用 awk 将第一个字符设置为小写 UNIX
- list - 如何检查列表是否不包含 Thymeleaf 中的值?
- python - 如何拆分字符串并从 Python 中的分隔字符串中只取一个?
- android - 如何使用 react-native-ble-manager 读取通用访问服务/特征