bash /usr/bin/env 错误的解释器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10525603/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
/usr/bin/env bad interpreter
提问by Zach
Trying to get Amazon's EC2 command line tools to work. This is what my .bash_profile looks like. I get the error: /users/zmjones/.ec2/bin/ec2-add-keypair: /usr/bin/env: bad interpreter: Operation not permitted
试图让亚马逊的 EC2 命令行工具工作。这就是我的 .bash_profile 的样子。我收到错误:/users/zmjones/.ec2/bin/ec2-add-keypair: /usr/bin/env: bad interpreter: Operation not allowed
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/opt/local/bin:$PATH
PATH=/opt/local/sbin:/usr/local/bin:/usr/x11/bin:/usr/texbin:$PATH
PATH=/usr/local/texlive/2011/bin/x86_64-darwin:$PATH
PATH=/Library/Frameworks/EPD64.framework/Versions/Current/bin:$PATH
EC2_HOME=~/.ec2
PATH=$PATH:$EC2_HOME/bin
EC2_PRIVATE_KEY=`ls $EC2_HOME/pk-*.pem`
EC2_CERT=`ls $EC2_HOME/cert-*.pem`
JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home/
export PATH
Does anybody see anything wrong with this? I am not sure what I doing wrong.
有人看到这有什么问题吗?我不确定我做错了什么。
Output of ls -l /usr/bin/env
输出 ls -l /usr/bin/env
-r-xr-xr-x 1 root wheel 34720 Sep 8 2011 /usr/bin/env
zmjones-mbp:.ec2 zmjones$ /usr/bin/env
TERM_PROGRAM=iTerm.app
TERM=xterm
SHELL=/bin/bash
TMPDIR=/var/folders/x3/vrw5029d1rj9xblj8bmxl0m00000gn/T/
Apple_PubSub_Socket_Render=/tmp/launch-91y0bp/Render
OLDPWD=/Users/zmjones
USER=zmjones
COMMAND_MODE=unix2003
SSH_AUTH_SOCK=/tmp/launch-H3JJsl/Listeners
__CF_USER_TEXT_ENCODING=0x1F5:0:0
Apple_Ubiquity_Message=/tmp/launch-n2bT2X/Apple_Ubiquity_Message
PATH=/users/zmjones/.ec2/bin:/Library/Frameworks/EPD64.framework/Versions/Current/bin:/usr/local/texlive/2011/bin/x86_64-darwin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/x11/bin:/usr/texbn
PWD=/Users/zmjones/.ec2
JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home/
LANG=en_US.UTF-8
ITERM_PROFILE=Default
SHLVL=1
HOME=/Users/zmjones
ITERM_SESSION_ID=w0t0p0
LOGNAME=zmjones
EC2_PRIVATE_KEY=pk-mykey.pem
DISPLAY=/tmp/launch-6kkP5t/org.x:0
EC2_CERT=cert-mycert.pem
_=/usr/bin/env
Partial solution: tr -d '\r' < /users/zmjones/.ec2/bin/ec2-add-keypair > /users/zmjones/.ec2/bin/ec2-add-keypair
部分解决方案: tr -d '\r' < /users/zmjones/.ec2/bin/ec2-add-keypair > /users/zmjones/.ec2/bin/ec2-add-keypair
This seems to allow the commands to execute, but they now don't work. For example, I downloaded a new copy of the ec2 api tools, put them in ~/.ec2tried ec2-describe-images -o amazonand got the bad interpreter error. I renamed ec2-describe-imagesto ec2-describe-images.bakran the trcommand listed above and tried it again. I then receive a permission denied error. When I run it with sudo it tells me that EC2_HOMEisn't set, but echo $EC2_HOMEindicates that it is. I ran chmod +x ec2-describe-imagesand now I am back to the same bad interepreter error.
这似乎允许命令执行,但它们现在不起作用。例如,我下载了 ec2 api 工具的新副本,将它们放入~/.ec2尝试ec2-describe-images -o amazon并得到了错误的解释器错误。我重命名ec2-describe-images以ec2-describe-images.bak运行tr上面列出的命令并再次尝试。然后我收到一个permission denied error. 当我使用 sudo 运行它时,它告诉我EC2_HOME未设置,但echo $EC2_HOME表示已设置。我跑了chmod +x ec2-describe-images,现在我又回到了同样的错误解释器错误。
回答by Johnsyweb
/users/zmjones/.ec2/bin/ec2-add-keypairhas DOS line-endings.
/users/zmjones/.ec2/bin/ec2-add-keypair有 DOS行结尾。
To fix:
修理:
mv /users/zmjones/.ec2/bin/ec2-add-keypair /users/zmjones/.ec2/bin/ec2-add-keypair.bak
tr -d '\r' < /users/zmjones/.ec2/bin/ec2-add-keypair.bak > /users/zmjones/.ec2/bin/ec2-add-keypair
回答by Martin Tapp
This happened to me on Windows because I had the wrong header in my bash files. I had
#!/usr/bin/bashinstead of #!/usr/bin/env bashwhich is the portable version.
这在 Windows 上发生在我身上,因为我的 bash 文件中有错误的标头。我有
#!/usr/bin/bash而不是#!/usr/bin/env bash便携式版本。
回答by user1257143
I got the exactly the same problem.
我遇到了完全相同的问题。
The CAUSE of the problem is the "unarchiver tool".
问题的原因是“解压缩工具”。
I've installed a third party unarchiver tool. It might change the line-endings of the files during the unzipping process.
我已经安装了第三方解压缩工具。它可能会在解压缩过程中更改文件的行尾。
After I realized this, I deleted this tool and re-unziped the EC2 zip ball using the native unzip tool. And the problem was solved.
意识到这一点后,我删除了这个工具,并使用本机解压工具重新解压了 EC2 zip 球。问题就解决了。
Hope this might be useful for you guys with the same problem.
希望这对有同样问题的人有用。

