65

I am a beginner on Play framework . I just extract Play framework files and extracted them and gave the path of play directory in $PATH global variable. After this when I run the the command on ubuntu play help, its giving me below error:

/usr/bin/env: sh: No such file or directory

Any clue why I am facing this error and how to resolve it ?

Mandar Pande
  • 12,250
  • 16
  • 45
  • 72
mathlearner
  • 7,509
  • 31
  • 126
  • 189

11 Answers11

118

This error usually happens if the script has windows line endings instead of unix line endings.

Try running dos2unix on the script and try running your command again to see if you get the same error.

dos2unix [filename]
Babatunde Adeyemi
  • 14,360
  • 4
  • 34
  • 26
  • 7
    This is the solution. I copied over the file from a windows machine. Installing and running dos2unix on the file enabled it to run without issues. – johnny Jul 06 '16 at 10:57
  • If on macOS, you won't have dos2unix by default but see https://stackoverflow.com/a/23831111/31629 for a solution. – Ken Sep 14 '18 at 22:56
22

I had the same problem, and resolved it using Notepad++, by clicking Edit -> EOL Conversion -> Unix and then save the file.

Laloi
  • 506
  • 1
  • 4
  • 12
4

I had the same error. I am using Windows Subsystem for Linux. First I tried removing the Windows Lineendings by entering tr -d '\r' < input.sh > output.sh. This did not help. In fact the path actually did not exist instead of #!/usr/bin/env bash, I needed to use #!/usr/bin/bash in the first line of my script.

Paul
  • 571
  • 3
  • 17
3

To resolve env: sh\r: No such file or directory issue:

Sometimes when files are transferred between different operating systems, the line endings can get converted to the wrong format, which can cause issues with shell scripts. Running dos2unix on the affected files is a quick and easy way to fix the line ending format and ensure that shell scripts can be executed without errors.

In my case, it was a transfer from Windows to MacOS.

This helped me:

  1. Install brew install dos2unix
  2. Convert all .sh files in repo: find . -type f -name '*.sh' -exec dos2unix {} \;
  3. Conver all your hooks. I have one hook so I run only one command: dos2unix .husky/pre-commit

Hope it'll help you.

Coffee-Tea
  • 1,139
  • 9
  • 10
  • I know you're not supposed to say thanks here, but this was perfect for me so thank you for being so helpful with your `commands` / suggestions – thathurtabit Aug 12 '23 at 10:50
2

$PATH environment variable is set in ~/.bashrc, ~/.bash_profile or ~/.profile.

source the relevant configuration file or start a new bash terminal should solve the problem.

Mingyu
  • 31,751
  • 14
  • 55
  • 60
1

Just change the sh terminal to bash using this link and everything should be fine.

1. Change user entry in /etc/passwd
a) edit /etc/passwd using any editor

$ vi /etc/passwd
b) find the line that belongs to the user (foo) that we about to modify
foo:x:1001:1001::/home/foo:/bin/sh
c) change from /bin/sh to /bin/bash
foo:x:1001:1001::/home/foo:/bin/bash
d) save
e) Logout and login back

2. Use chsh command
a) type chsh
$ chsh
b) You will be asked for password. Enter your password
c) This screen will appear
Enter the new value, or press ENTER for the default
Login Shell [/bin/sh]:
d) Put /bin/bash at the menu and press Enter
Bird87 ZA
  • 2,313
  • 8
  • 36
  • 69
mathlearner
  • 7,509
  • 31
  • 126
  • 189
1

For peoples in Windows using Visual Studio Git module, if you encounter this error

enter image description here

You should setup C:\Program Files\Git\bin for Path in Environment Variables System

enter image description here

Laurent
  • 662
  • 2
  • 10
  • 13
  • This worked for me, however my git\bin resides in another folder. use cmd to find your path using: c:>where git – Emil G Jun 02 '23 at 13:03
0

Got this error when running on new Macbook Pro, because the default shell is now ZSH instead of Bash. Just type bash to enter bash shell, and run your script as normal.

Janac Meena
  • 3,203
  • 35
  • 32
0

This can also happen if your file is UTF-8 encoded with a "BOM" header (byte-order-mark) at the beginning of the file. Use your editor to "remove bom".

Bouke Versteegh
  • 4,097
  • 1
  • 39
  • 35
0

I ran into a very similar error while using Windows Subsystem for Linux (WSL2).

Setting git autocrlf to false via git config --global core.autocrlf false, and re-cloning the repository did the trick for me.

I've also seen folks recommend preventing WSL from adding Windows paths to PATH env var (read more).

awoosnam
  • 81
  • 3
-1

i was getting slimier error in react-native because i forgot to add environment variable for android studio

add in .bashrc

 export ANDROID_HOME=$HOME/Android/Sdk
 export PATH=$PATH:$ANDROID_HOME/emulator
 export PATH=$PATH:$ANDROID_HOME/tools
 export PATH=$PATH:$ANDROID_HOME/tools/bin
 export PATH=$PATH:$ANDROID_HOME/platform-tools
Saeed
  • 3,294
  • 5
  • 35
  • 52
Aditya parmar
  • 1
  • 1
  • 1
  • 2
  • 1
    You should not need to `export` anything more than once, and `PATH` will already have been `export`ed by your shell. – tripleee Jun 22 '21 at 10:43
  • i was using react-native and the official doc say that https://reactnative.dev/docs/environment-setup – Aditya parmar Jul 11 '21 at 03:46