linux - Bash 脚本 : bad interpreter

标签 linux bash mono scripting

问题:我收到此错误消息:

export: bad interpreter: No such file or directory

当我执行这个 bash 脚本时:

#!/bin/bash
MONO_PREFIX=/opt/mono-2.6
GNOME_PREFIX=/opt/gnome-2.6
export DYLD_LIBRARY_PATH=$MONO_PREFIX/lib:$DYLD_LIBRARY_PATH
export LD_LIBRARY_PATH=$MONO_PREFIX/lib:$LD_LIBRARY_PATH
export C_INCLUDE_PATH=$MONO_PREFIX/include:$GNOME_PREFIX/include
export ACLOCAL_PATH=$MONO_PREFIX/share/aclocal
export PKG_CONFIG_PATH=$MONO_PREFIX/lib/pkgconfig:$GNOME_PREFIX/lib/pkgconfig
PATH=$MONO_PREFIX/bin:$PATH
PS1="[mono-2.6] \w @ "

但 bash 路径似乎是正确的:

asshat@IS1300:~/sources/mono-2.6# which bash
/bin/bash

asshat@IS1300:~# cd sources/
asshat@IS1300:~/sources# cd mono-2.6/
asshat@IS1300:~/sources/mono-2.6# ./mono-2.6-environment
export: bad interpreter: No such file or directory
asshat@IS1300:~/sources/mono-2.6# ls
download  mono-2.4  mono-2.4-environment  mono-2.6  mono-2.6-environment
asshat@IS1300:~/sources/mono-2.6# cp mono-2.6-environment mono-2.6-environment.sh
asshat@IS1300:~/sources/mono-2.6# ./mono-2.6-environment.sh
export: bad interpreter: No such file or directory
asshat@IS1300:~/sources/mono-2.6# ls
download  mono-2.4-environment  mono-2.6-environment
mono-2.4  mono-2.6              mono-2.6-environment.sh
asshat@IS1300:~/sources/mono-2.6# bash mono-2.6-environment
asshat@IS1300:~/sources/mono-2.6#

我做错了什么?或者这是 Lucid Lynx 的错误?

我做了 chmod + x

最佳答案

第一行,#!/bin/bash , 告诉 Linux 在哪里可以找到解释器。该脚本也应该可以执行 chmod +x script.sh ,看来你做到了。

很可能您使用 Windows 编辑器创建了此文件,该编辑器将放置一个 <cr><lf>在每一行的末尾。这是dos/windows下的标准。 OS X 将放置一个 <cr>在每一行的末尾。然而,在 Unix/Linux 下,标准是只放一个 <lf>。在行尾。

Linux 现在正在寻找一个名为 /bin/bash<cr> 的文件解释文件, 其中 <cr>是一个回车符,在Linux下是一个有效的文件字符。这样的文件不存在。因此错误。

解决方案: 在 Linux 上用编辑器编辑文件,去掉多余的 <cr> .在 Windows 上编辑文件时通常可以使用的一种工具是 dos2unix .

关于linux - Bash 脚本 : bad interpreter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2841593/

相关文章:

bash - 如何执行shell脚本?

android - Monodroid - 处理 ListAdapter 行内的点击事件

linux - 将 OpenLDAP 目录导入 OSX Open Directory

linux - 在 Windows 10 中模拟启用类似 Linux 的管理员权限

linux - 使用 ls -R 列出没有子目录信息的文件

python - 脚本(python,applescript,bash)使用pdf2tiff自动将一组金字塔平铺图像转换为一组大tiff?

linux - 如何修复 "E: The list of sources could not be read"无法读取错误?

linux - 为什么 bash 脚本中需要 $(( ... )) ?

Android 垃圾收集器 Nursery Full

c# - Mono C# 的 CSS 样式