linux - "cannot execute binary file"尝试在 linux 上运行 shell 脚本时

标签 linux bash shell

我是 linux 和 shell 脚本的新手。 我正在尝试使用以下命令在 Linux 上从安全 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 path/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-Again shell 脚本文本可执行文件”

请就我如何尝试执行 shellscript 提供任何建议。

最佳答案

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

chmod +x path/to/mynewshell.sh

并运行它

/path/to/mynewshell.sh

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

关于linux - "cannot execute binary file"尝试在 linux 上运行 shell 脚本时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37378375/

相关文章:

Linux命令来抓取文件之间相似的行

bash - 我如何通过管道传输 stderr 而不是 stdout?

c# - 在 C# 程序中使用 bash(cygwin)

php - 使用多行 PHP 变量作为执行 bash 脚本的参数

linux - 从 UTC 到纪元的转换 shell 脚本或 awk

linux - 在 .*sh 文件中启动一个新的 shell

c++ - 在另一台计算机上运行 a.out

linux - 如何检查进程是否正在运行 - Linux

php - 如何在 Linux 上使用 PHP 从本地主机发送电子邮件

bash - 从 Jenkins 调用时 Tomcat 启动脚本不起作用