我是Play框架的初学者。我刚刚提取了Play框架文件并将它们解压缩,并将play目录的路径赋给了$PATH
全局变量。在此之后,当我在Ubuntu上运行命令play help
时,它会给我以下错误:
/usr/bin/env: sh: No such file or directory
有什么线索可以解释我为什么会遇到这个错误,并且如何解决它吗?
我是Play框架的初学者。我刚刚提取了Play框架文件并将它们解压缩,并将play目录的路径赋给了$PATH
全局变量。在此之后,当我在Ubuntu上运行命令play help
时,它会给我以下错误:
/usr/bin/env: sh: No such file or directory
有什么线索可以解释我为什么会遇到这个错误,并且如何解决它吗?
如果脚本使用的是Windows行结束符而不是Unix行结束符,通常会出现此错误。
尝试对脚本运行dos2unix,然后再次运行命令,看看是否会出现相同的错误。
dos2unix [filename]
我曾经遇到同样的问题,并使用 Notepad++ 解决了它,具体方法是点击“编辑”(Edit)->“行尾转换”(EOL Conversion)->“Unix”,然后保存文件。
我遇到了相同的错误。我正在使用 Windows Subsystem for Linux.
首先,我尝试通过输入 tr -d '\r' < input.sh > output.sh
来移除Windows行末标识符。
但这并没有帮助解决问题。
实际上,问题出在路径不存在。我需要在脚本的第一行使用#!/usr/bin/bash
而不是#!/usr/bin/env bash
。
解决env: sh\r: No such file or directory
问题:
有时在不同操作系统之间传输文件时,行尾可能会被转换为错误的格式,这可能会导致 shell 脚本出现问题。在受影响的文件上运行 dos2unix 是修复行尾格式并确保 shell 脚本无误执行的快速简便方法。
在我的情况下,是从 Windows 到 MacOS 进行的转移。
以下步骤对我有帮助:
brew install dos2unix
.sh
文件:find . -type f -name '*.sh' -exec dos2unix {} \;
dos2unix .husky/pre-commit
希望它能够帮助到您。
$PATH
环境变量设置在~/.bashrc
、~/.bash_profile
或~/.profile
文件中。
source
相关配置文件或启动新的bash终端即可解决问题。
只需使用此链接将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
bash
进入bash shell,并像往常一样运行您的脚本即可。如果文件开头有 UTF-8的 "BOM" 头部(字节顺序标记),也会出现这种情况。请使用编辑器“删除bom”。