Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
&引用;无法执行二进制文件";尝试在linux上运行shell脚本时_Linux_Bash_Shell - Fatal编程技术网

&引用;无法执行二进制文件";尝试在linux上运行shell脚本时

&引用;无法执行二进制文件";尝试在linux上运行shell脚本时,linux,bash,shell,Linux,Bash,Shell,我对linux和shell脚本非常陌生。 我正在尝试使用以下命令从linux上的secure shell(ssh)运行shellscript: chmod +x path/to/mynewshell.sh sh path/to/mynewshell.sh 我得到这个错误: path/to/mynewshell.sh: path/to/mynewshell.sh: cannot execute binary file. 已尝试使用此命令: bash path/to/mynewshell.sh

我对linux和shell脚本非常陌生。 我正在尝试使用以下命令从linux上的secure shell(ssh)运行shellscript:

chmod +x path/to/mynewshell.sh

sh path/to/mynewshell.sh
我得到这个错误:

path/to/mynewshell.sh: path/to/mynewshell.sh: cannot execute binary file.
已尝试使用此命令:

bash path/to/mynewshell.sh
我也犯了同样的错误

尝试使用以下命令:
su-myusername sh path/to/mynewshell.sh
它询问我的密码并给我这个错误:
没有这样的文件或目录

1.cat-v路径/to/mynewshell.sh的结果是: ^@^@^@^@^@^@^@^@Rscript“$dir”/diver_script.R 完成

2.尝试“less path/to/mynewshell.sh”时,我在终端上得到了以下信息:

#!/bin/bash/Rscript^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
for dir in /path/to/* ; do 
^@^@^@^@^@^@^@^@Rscript "$dir"/myRscript.R
done
3.当我运行文件path/to/mynewshell.sh时:我得到了这个“Bourne再次shell脚本文本可执行文件”


请给出如何尝试执行shellscript的建议。

chmod-x
从文件中删除执行权限。这样做:

chmod +x path/to/mynewshell.sh
并运行它

/path/to/mynewshell.sh

正如错误报告所说,您的脚本实际上不是一个脚本,而是一个二进制文件。

我在PowerShell中通过bash解释器运行shell脚本时遇到了相同的错误。我在shell脚本上运行了
dos2unix myscript.sh
,现在它运行正常。

来自

这是因为文件是压缩的,如扩展名
.xz
所示。您需要先删除压缩,然后才能使用该文件

xz -d ./run_me.sh.xz
chmod +x ./run_me.sh  # probably not necessary if you already did that before
./run_me.sh

其他压缩方案,如
gzip
.gz
扩展)、
bzip2
.bz2
扩展)等表现类似;你只需要知道解压命令的名称,这对谷歌来说当然很容易。

对其他有问题的人来说

我试图运行一个转换为shell脚本的16位unicode文本文件,但这不起作用,因为所有16位unicode文本文件在开始时都有一个0xFFFE标记,使得mac os不喜欢该文件,这会导致“无法执行二进制文件”错误

打开文本文件,点击顶部的“格式”,向下点击“生成纯文本”

打开您的终端类型
chmod 777/path/to/file.sh


放入terminal:
/path/to/file.sh
运行它

该脚本根本不是shell脚本。 shell脚本通常可读并包含shell代码。 cat命令显示的输出看起来确实是某种二进制文件。 正如一些人所指出的,这可能是因为复制时存在文件转换问题,但在我看来,它更像是一个实际的二进制文件

您可以使用file命令检查其标识,以便:

file path/to/mynewshell.sh
从一个干净的脚本开始重写代码,看起来你只是想在一个目录中运行一些R脚本


确保R脚本指向正确的R脚本执行器。

/path/to/
还是
/path/toscript/
?您似乎混淆了它们。请尝试
less path/toscript/mynewshell.sh
,查看该文件是否实际上是一个shell脚本。编辑问题并添加
cat-v path/toscript/mynewshell.sh
的结果。您是否从windows系统导入此脚本?第一行是空的吗?否则它是否以shebang和有效命令开始?或者,运行
文件路径/toscript/mynewshell.sh
并编辑您的问题以包含输出。该脚本文件已严重损坏。我们可以试着猜出文件中应该有什么,但是如果你能找到原始来源并检索到一份未损坏的副本,你会过得更好。是的,但是当使用
sh
调用脚本时,可执行位不是必需的,所以这不应该是这里的问题。我给出了命令chmod+x path/toscript/mynewshell.sh/path/to/mynewshell.sh,我得到:/path/to/mynewshell.sh:不是目录。@RBud
/path/to/mynewshell.sh
,请尝试使用正确的路径,否则,任何事情都不会发生……无论你希望实现什么,
chmod 777
都是错误和危险的。您绝对不希望在任何情况下向所有用户授予对可执行文件或系统文件的写入权限。您将希望尽快恢复到sane权限(对于您的用例,可能是
chmod 755
),并在再次尝试使用之前了解Unix权限模型。如果这种情况发生在具有Internet访问权限的系统上,请检查入侵者是否可能利用此漏洞升级其权限。
file path/to/mynewshell.sh