空 Bash 行抛出错误
Empty Bash line throws error
我写了一个小的 NEOS 备份脚本来转储我的 mysql 数据库并压缩它..
在我的笔记本电脑 (Deepin OS) 上脚本运行良好但在服务器上它抛出错误...
https://gist.github.com/breadlesscode/2f2e274a3c9314b99ac71fc6b2afb07a
空行抛出错误?!我不知道为什么。我试过不同的行尾,但它没有用。
bash -x ./crons/BackupNeos.sh 输出:
+ BACKUP_FOLDER=%s_NEOS_Backup
+ NEOS_ROOT=$'/html/neos\r'
+ BACKUP_ROOT=$'/html/backups\r'
+ NEOS_PACKAGE=$'My.Package\r'
+ COMPRESS_BACKUP=$'true\r'
+ NEOS_FLOW_EXPORT=$'true\r'
+ MYSQL_FULL_BACKUP=$'true\r'
+ MYSQL_HOST=$'server\r'
+ MYSQL_USER=$'user\r'
+ MYSQL_PW=$'password\r'
+ MYSQL_DB=$'database\r'
+++ date +%Y-%m-%d_%H-%M-%S
++ printf %s_NEOS_Backup 2017-01-15_18-53-30
+ BACKUP_FOLDER=$'2017-01-15_18-53-30_NEOS_Backup\r'
++ printf %s/%s $'/html/backups\r' $'2017-01-15_18-53-30_NEOS_Backup\r'
+ BACKUP_FOLDER_PATH=$'/html/backups\r/2017-01-15_18-53-30_NEOS_Backup\r\r'
+ $'\r'
: Command not found.le 18:
' printf 'Backup script start:\n\n
Backup script start:
+ cd $'/html/backups\r\r'
: File or directory not foundtml/backups
' printf 'Create backup folder...
+ mkdir $'2017-01-15_18-53-30_NEOS_Backup\r\r'
' printf 'done!\n
done!
+ $'\r'
: Command not found.le 24:
./crons/BackupNeos.sh: Zeile 51: Syntax Error: worong eol.
谁能帮帮我?
'\r'
是 Windows EOL 标记,它在 unix-like 操作系统中不起作用。
尝试
dos2unix ./crons/BackupNeos.sh
这会将 EOL 转换为正确的。
使用 sed
的替代方法:
sed -i 's/^M$//' ./crons/BackupNeos.sh
我写了一个小的 NEOS 备份脚本来转储我的 mysql 数据库并压缩它..
在我的笔记本电脑 (Deepin OS) 上脚本运行良好但在服务器上它抛出错误...
https://gist.github.com/breadlesscode/2f2e274a3c9314b99ac71fc6b2afb07a
空行抛出错误?!我不知道为什么。我试过不同的行尾,但它没有用。
bash -x ./crons/BackupNeos.sh 输出:
+ BACKUP_FOLDER=%s_NEOS_Backup
+ NEOS_ROOT=$'/html/neos\r'
+ BACKUP_ROOT=$'/html/backups\r'
+ NEOS_PACKAGE=$'My.Package\r'
+ COMPRESS_BACKUP=$'true\r'
+ NEOS_FLOW_EXPORT=$'true\r'
+ MYSQL_FULL_BACKUP=$'true\r'
+ MYSQL_HOST=$'server\r'
+ MYSQL_USER=$'user\r'
+ MYSQL_PW=$'password\r'
+ MYSQL_DB=$'database\r'
+++ date +%Y-%m-%d_%H-%M-%S
++ printf %s_NEOS_Backup 2017-01-15_18-53-30
+ BACKUP_FOLDER=$'2017-01-15_18-53-30_NEOS_Backup\r'
++ printf %s/%s $'/html/backups\r' $'2017-01-15_18-53-30_NEOS_Backup\r'
+ BACKUP_FOLDER_PATH=$'/html/backups\r/2017-01-15_18-53-30_NEOS_Backup\r\r'
+ $'\r'
: Command not found.le 18:
' printf 'Backup script start:\n\n
Backup script start:
+ cd $'/html/backups\r\r'
: File or directory not foundtml/backups
' printf 'Create backup folder...
+ mkdir $'2017-01-15_18-53-30_NEOS_Backup\r\r'
' printf 'done!\n
done!
+ $'\r'
: Command not found.le 24:
./crons/BackupNeos.sh: Zeile 51: Syntax Error: worong eol.
谁能帮帮我?
'\r'
是 Windows EOL 标记,它在 unix-like 操作系统中不起作用。
尝试
dos2unix ./crons/BackupNeos.sh
这会将 EOL 转换为正确的。
使用 sed
的替代方法:
sed -i 's/^M$//' ./crons/BackupNeos.sh