title: Calling bash script inside AWS CodeBuild: script could not be found
body: <p>I'm trying to run a small bash script inside my CodeBuild process as per the <a href="https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-cmd.html" rel="nofollow noreferrer">AWS documentation</a> and <a href="https://www.reddit.com/r/aws/comments/b4y3xr/running_bashsh_on_codebuild/" rel="nofollow noreferrer">this</a>.</p>
  <p><code>deploy.sh</code> can be found in the <code>src/</code> directory:</p>
  <pre><code>#!/bin/bash
  
  pwd=$PWD
  
  for dir in */ ; do
    target=&quot;$pwd/${dir%/}&quot;
    cd &quot;$target&quot;
    npm install
    sls deploy &amp;&amp; sls s3deploy
  done
  </code></pre>
  <p>buildspec file:</p>
  <pre><code>version: 0.2
  
  phases:
    install:
      runtime-versions:
        nodejs: 10
      commands:
      - cd backend/functions/src
      - npm install serverless
    build:
      commands:
      - ls
      - ./deploy.sh
  </code></pre>
  <p>after the <code>ls</code> command above in the logs, I can see that <code>deploy.sh</code> is there in the current directory.</p>
  <p>Error:</p>
  <blockquote>
  <p>/codebuild/output/tmp/script.sh: 4: /codebuild/output/tmp/script.sh: ./deploy.sh: not found</p>
  </blockquote>
  <p>I've also tried using the command <code>/bin/bash deploy.sh</code> but this results in another error:</p>
  <blockquote>
  <p>deploy.sh: line 2: $'\r': command not found</p>
  <p>deploy.sh: line 4: $'\r': command not found</p>
  <p>deploy.sh: line 7: $'\r': command not found</p>
  <p>deploy.sh: line 8: syntax error near unexpected token `$'do\r''</p>
  <p>deploy.sh: line 8: `for dir in */ ; do</p>
  </blockquote>