微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

尝试在linux上运行shell脚本时“无法执行二进制文件”

我是linux和shell脚本编程的新手.
我试图使用以下命令从Linux上的安全shell(ssh)运行一个shellcript:

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
DONE

2.当我尝试’less path / to / Mynewshell.sh’时,我在终端上得到了这个:

#!/bin/bash/Rscript^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
for dir in /path/to/* ; do 
^@^@^@^@^@^@^@^@Rscript "$dir"/myRscript.R
done

3.当我运行文件路径/到/ Mynewshell.sh时:我得到了这个“Bourne-Again shell脚本文本可执行文件

请提供有关如何尝试执行shellscript的任何建议.

最佳答案
chmod -x从文件删除执行权限.做这个:

chmod +x path/to/Mynewshell.sh

并运行它

/path/to/Mynewshell.sh

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

原文地址:https://www.jb51.cc/linux/440339.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐