我是 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/