在 bash 脚本中执行 find 时出现 $'\r': 命令未找到错误

在 bash 脚本中执行 find 时出现 $'\r': 命令未找到错误

我编写了以下脚本;出于简单性和隐私原因对其进行了修改:

FILES_ROOT='/data/FILES'

BACK_B2B_RETURNS_S="$FILES_ROOT"'/wms-m-company/w2z/b2breturns/backup'
BACK_B2B_RETURNS_D="$FILES_ROOT"'/wms-d-company/w-to-z/backup/m-company/b2b-delivery-confirmations'
find "$BACK_B2B_RETURNS_S" -maxdepth 1 -type f -exec mv {} "$BACK_B2B_RETURNS_D" \;

LOG_B2B_RETURNS_S="$FILES_ROOT"'/wms-m-company/w2z/b2breturns/log'
LOG_B2B_RETURNS_D="$FILES_ROOT"'/wms-d-company/w-to-z/backup/m-company/b2b-delivery-confirmations/log'
find "$LOG_B2B_RETURNS_S" -maxdepth 1 -type f -exec mv {} "$LOG_B2B_RETURNS_D" \;

执行脚本出现此错误:

-bash: $'\r': command not found
-bash: $'\r': command not found
find: missing argument to `-exec'
Try 'find --help' for more information.
-bash: $'\r': command not found
find: missing argument to `-exec'
Try 'find --help' for more information.

我不明白为什么。通常,我会使用终端进行调试,但这不是一个选项,因为当我在终端中逐行复制/粘贴/执行时,它才有效。

有谁知道这个脚本有什么问题吗?

答案1

脚本源中有 MSWin 行结尾。使用 dos2unix 或 fromdos 来修复它们。

相关内容