空Bash行抛出错误

时间:2017-01-15 17:57:18

标签: linux bash shell neoscms

我写了一个小的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.

任何人都可以帮助我?

1 个答案:

答案 0 :(得分:6)

'\r'是Windows EOL标记,在类似Unix的操作系统中不起作用。

尝试

dos2unix ./crons/BackupNeos.sh

将EOL转换为正确的。

使用sed的替代方法:

sed -i 's/^M$//' ./crons/BackupNeos.sh