Founding prices until 15 December: 30% off Pro, locked for life. See pricing

$ … /bin/bash^M: bad interpreter: No such file or directory

'bad interpreter: ^M': Windows line endings in a script

The script has Windows line endings, so Linux looks for an interpreter called "bash\r".

Linux

What it means

The first line #!/bin/bash ends with \r\n when the file was saved on Windows. The kernel reads the interpreter as "/bin/bash\r", which doesn't exist. Other variants: "env: 'python3\r': No such file".

Causes and fixes

Most likely first. Run the check, and if it matches, apply the fix.

1. The file was edited or committed with CRLF line endings

Check:

file script.sh; head -1 script.sh | od -c | head -2

Fix: Convert it (sed -i 's/\r$//' script.sh or dos2unix) and add *.sh text eol=lf to .gitattributes.

2. The interpreter path really doesn't exist on this system

Check:

head -1 script.sh; command -v bash python3

Fix: Use #!/usr/bin/env bash, or install the interpreter.

Fix it yourself

A live machine in your browser with this problem already on it. The grader checks the result.

Open the lab

No account needed for your first tries.

Related errors

  • Permission denied

    The user the process runs as lacks the read, write or execute right on the file or a directory on its path.