“无法执行二进制文件"尝试在Linux上运行Shell脚本时 [英] "cannot execute binary file" when trying to run a shell script on linux
问题描述
我对linux和shell编写非常陌生. 我正在尝试使用以下命令从linux上的安全shell(ssh)运行shellscript:
I am very new to linux and shell scriprting. I am trying to run a shellscript from secure shell (ssh) on linux using following commands:
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
它要求输入密码并给我这个错误:no such file or directory
.
Tried with this command: su - myusername sh path/to/mynewshell.sh
It is asking for my password and giving me this error: no such file or directory
.
1.cat -v path/to/mynewshell.sh的结果是: ^ @ ^ @ ^ @ ^ @ ^ @ ^ @ ^ @ ^ @ Rscript"$ dir"/diver_script.R 完成
1.The result of cat -v path/to/mynewshell.sh is: ^@^@^@^@^@^@^@^@Rscript "$dir"/diver_script.R done
2.在尝试"less path/to/mynewshell.sh"时,我在终端上收到了这个信息:
2.When tried 'less path/to/mynewshell.sh' i got this on my terminal:
#!/bin/bash/Rscript^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
for dir in /path/to/* ; do
^@^@^@^@^@^@^@^@Rscript "$dir"/myRscript.R
done
3.当我运行文件路径/to/mynewshell.sh时:我得到了这个"Bourne-Again Shell脚本文本可执行文件"
3.When i ran file path/to/mynewshell.sh : i got this "Bourne-Again shell script text executable"
请提供有关如何尝试执行shellscript的任何建议.
Please give any advice on how I can try executing the shellscript.
推荐答案
chmod -x
从文件中删除执行权限.这样做:
chmod -x
removes execution permission from a file. Do this:
chmod +x path/to/mynewshell.sh
并使用
/path/to/mynewshell.sh
如错误报告所述,您的脚本实际上不是脚本,而是二进制文件.
As the error report says, you script is not actually a script, it's a binary file.
这篇关于“无法执行二进制文件"尝试在Linux上运行Shell脚本时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!