bash: no such file or directory — how to fix

# Verify the file exists and check the exact path
ls -la script.sh

# Check for Windows line endings (CRLF) in the shebang line
file script.sh
# If it says "CRLF line terminators", convert:
sed -i 's/
//' script.sh
# or
dos2unix script.sh
-bash: ./script.sh: /bin/bash^M: bad interpreter: No such file or directory
# or simply
bash: ./script.sh: No such file or directory

The ^M (carriage return) means the file was created on Windows. The shebang interpreter path is /bin/bash which does not exist.

File really does not exist

# Show exact path and check for typos
pwd
ls -la
# Check hidden files
ls -la | grep script

Shebang points to wrong interpreter

# Check what interpreter is being used
head -1 script.sh
# #!/usr/bin/env bash   ← correct, portable
# #!/bin/bash           ← works on most Linux systems

# Find where bash actually is
which bash
# /usr/bin/bash   (not /bin/bash on some systems)

Wrong architecture binary

If you run a binary compiled for a different CPU architecture (e.g. arm64 on x86), you get this error.

file ./my-binary
# ELF 64-bit LSB executable, ARM aarch64 ← wrong arch for x86-64