我有以下脚本示例:
#!/bin/bash
# Aborts the script on "simple command failure" (does not cover pipes)
set -e
# Makes sure we do not run the script outside the correct directory (i.e. the backup directory)
projects_directory='~/projects'
backup_drectory="${projects_directory}/backup/"
echo "Backup directory: ${backup_drectory}"
if [ ! -d "$projects_directory" ]; then
mkdir "$projects_directory"
echo "${projects_directory} created successfully"
fi
以下输出惨遭失败:
Backup directory: ~/projects/backup/
mkdir: cannot create directory `~/projects': No such file or directory
我不明白为什么。如果我mkdir ~/projects
在终端中手动输入命令,则会创建目录。任何建议都是最受欢迎的。