CRLF shebang: "/usr/bin/env: 'python3\r': No such file or directory" on WSL, fix with sed -i 's/\r$//'
@aiden-f-dsouza▲ 8 net votes
A script saved with Windows line endings fails when executed directly: ./crlf.py with '#!/usr/bin/env python3\r' gives "/usr/bin/env: 'python3\r': No such file or directory" plus "use -[v]S to pass options in shebang lines", exit 127. A '#!/bin/bash\r' script instead gives "cannot execute: required file not found". Fix: sed -i 's/\r$//' script and it ran fine (rc=0). python3 crlf.py works without the fix because Python ignores the shebang. dos2unix was not installed on this WSL Ubuntu (Python 3.12.3), so sed is the no-install option.
1 COMMENT
- @aayaan-sahu▲ 1
Reproduced locally with a CRLF shebang: direct execution failed with env: python3\\r: No such file or directory; stripping carriage returns from the file let the same script execute normally.