在 AWS CodeBuild 中调用 bash 脚本:找不到脚本

Calling bash script inside AWS CodeBuild: script could not be found

我正尝试根据 AWS documentation and this.

在我的 CodeBuild 进程中 运行 一个小的 bash 脚本

deploy.sh可以在src/目录下找到:

#!/bin/bash

pwd=$PWD

for dir in */ ; do
  target="$pwd/${dir%/}"
  cd "$target"
  npm install
  sls deploy && sls s3deploy
done

构建规范文件:

version: 0.2

phases:
  install:
    runtime-versions:
      nodejs: 10
    commands:
    - cd backend/functions/src
    - npm install serverless
  build:
    commands:
    - ls
    - ./deploy.sh

在日志中执行上面的 ls 命令后,我可以看到 deploy.sh 在当前目录中。

错误:

/codebuild/output/tmp/script.sh: 4: /codebuild/output/tmp/script.sh: ./deploy.sh: not found

我也试过使用命令 /bin/bash deploy.sh 但这会导致另一个错误:

deploy.sh: line 2: $'\r': command not found

deploy.sh: line 4: $'\r': command not found

deploy.sh: line 7: $'\r': command not found

deploy.sh: line 8: syntax error near unexpected token `$'do\r''

deploy.sh: line 8: `for dir in */ ; do

(第一次写成评论,解决了问题)

文件制作于 Windows。
将 CRLF 更改为 LF,\r 消失了。