获取错误/ usr/bin/env:sh:运行命令播放时没有这样的文件或目录

Rit*_*tta 23 shell sh

我是Play框架的初学者.我只是提取Play框架文件并提取它们,并在$PATH全局变量中给出了播放目录的路径.在此之后,当我在ubuntu播放帮助上运行命令时,它给出了以下错误:

/usr/bin/env: sh: No such file or directory
Run Code Online (Sandbox Code Playgroud)

有什么线索我为什么会遇到这个错误以及如何解决它?

Bab*_*emi 59

如果脚本具有Windows行结尾而不是unix行结尾,则通常会发生此错误.

尝试在脚本上运行dos2unix并尝试再次运行命令以查看是否收到相同的错误.

dos2unix [filename]
Run Code Online (Sandbox Code Playgroud)

  • 这是解决方案.我从Windows机器上复制了文件.在文件上安装和运行dos2unix使其能够正常运行. (5认同)

Lal*_*loi 12

我遇到了同样的问题,并使用 Notepad++ 解决了它,方法是单击“编辑”->“EOL 转换”->“Unix”,然后保存文件。


Cof*_*Tea 5

要解决env: sh\r: No such file or directory问题:

有时,当文件在不同操作系统之间传输时,行结尾可能会转换为错误的格式,这可能会导致 shell 脚本出现问题。在受影响的文件上运行 dos2unix 是一种快速而简单的方法,可以修复行结束格式并确保 shell 脚本可以无错误地执行。

就我而言,这是从 Windows 转移到 MacOS。

这帮助了我:

  1. 安装brew install dos2unix
  2. 转换.sh存储库中的所有文件:find . -type f -name '*.sh' -exec dos2unix {} \;
  3. 转换你所有的钩子。我有一个钩子,所以我只运行一个命令:dos2unix .husky/pre-commit

希望它能帮助你。


Rit*_*tta 1

只需使用此链接将 sh 终端更改为 bash ,一切都会好起来的。

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
Run Code Online (Sandbox Code Playgroud)