我正在创建一个快速备份脚本,该脚本会将一些数据库转储到一个漂亮的/整洁的目录结构中,我意识到我需要在创建目录之前进行测试,以确保目录存在。我拥有的代码可以运行,但是似乎有更好的方法可以做到这一点。有什么建议?
[ -d "$BACKUP_DIR" ] || mkdir "$BACKUP_DIR"
[ -d "$BACKUP_DIR/$client" ] || mkdir "$BACKUP_DIR/$client"
[ -d "$BACKUP_DIR/$client/$year" ] || mkdir "$BACKUP_DIR/$client/$year"
[ -d "$BACKUP_DIR/$client/$year/$month" ] || mkdir "$BACKUP_DIR/$client/$year/$month"
[ -d "$BACKUP_DIR/$client/$year/$month/$day" ] || mkdir "$BACKUP_DIR/$client/$year/$month/$day"
3
unix.stackexchange.com/questions/49263/recursive-mkdir
—
Ciro Santilli郝海东冠状病六四事件法轮功