When I type Anything in Ubuntu it returns /usr/bin/env: ‘bash\r’: No such file or directory
I noticed the issues when I tried making a react app
npx create-react-app app_name
it returns /usr/bin/env: ‘bash\r’: No such file or directory
Then when tried to check the versions of npm or anything else
it returns /usr/bin/env: ‘bash\r’: No such file or directory
The only thing that has worked so far is navigating through directories and making new ones.
I don't know what to do. please help
CodePudding user response:
You have created an executable shell script with a shebang line #!/usr/bin/env bash
. But you have likely created it on Microsoft Windows, and the line endings are \r\n (i.e. CRLF), instead of \n (LF) on Linux.
This does not work with shell scripts: you have to change the line endings to \n (Notepad can do that, for instance). What happens is, Linux reads lines separated by \n, so the first line ends with bash\r, and this is not the name of a known executable.
Note: this will fail not only with bash, but any script using a shebang: that can be Perl, Python, R, etc. That's because whatever the programming language, the executable is not called, because it's not found.
Note also that those programming languages usually read happily files with \r\n line endings. It's really the shebang line (i.e. executable scripts) that causes this problem.