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:
我是linux和shell脚本编程的新手。我试图使用以下命令从Linux上的安全shell(ssh)运行一个shellcript:
chmod +x path/to/mynewshell.sh
sh path/to/mynewshell.sh
I get this error:
我收到此错误:
path/to/mynewshell.sh: path/to/mynewshell.sh: cannot execute binary file.
Tried using this command:
尝试使用此命令:
bash path/to/mynewshell.sh
I get the same error.
我犯了同样的错误。
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
.
试过这个命令:su - myusername sh path / to / mynewshell.sh它要求我输入密码并给我这个错误:没有这样的文件或目录。
1.The result of cat -v path/to/mynewshell.sh is: ^@^@^@^@^@^@^@^@Rscript "$dir"/diver_script.R done
1. cat -v path / to / mynewshell.sh的结果是:^ @ ^ @ ^ @ ^ @ ^ @ ^ @ ^ @ ^ @ Rscript“$ dir”/diver_script.R done
2.When tried 'less path/to/mynewshell.sh' i got this on my terminal:
2.当我尝试'less path / to / mynewshell.sh'时,我在终端上得到了这个:
#!/bin/bash/Rscript^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
for dir in /path/to/* ; do
^@^@^@^@^@^@^@^@Rscript "$dir"/myRscript.R
done
3.When i ran file path/to/mynewshell.sh : i got this "Bourne-Again shell script text executable"
3.当我运行文件路径/到/ mynewshell.sh时:我得到了这个“Bourne-Again shell脚本文本可执行文件”
Please give any advice on how I can try executing the shellscript.
请提供有关如何尝试执行shellscript的任何建议。
3 个解决方案
#1
10
chmod -x
removes execution permission from a file. Do this:
chmod -x从文件中删除执行权限。做这个:
chmod +x path/to/mynewshell.sh
And run it with
并运行它
/path/to/mynewshell.sh
As the error report says, you script is not actually a script, it's a binary file.
正如错误报告所说,你的脚本实际上不是一个脚本,它是一个二进制文件。
#2
1
I was getting the same error running my shell script through a bash interpreter in PowerShell. I ran dos2unix myscript.sh
on the shell script, and now it runs ok.
我通过PowerShell中的bash解释器运行我的shell脚本时遇到了同样的错误。我在shell脚本上运行了dos2unix myscript.sh,现在运行正常。
#3
0
From a proposed duplicate:
从拟议的副本:
run_me.sh.xz: run_me.sh.xz: cannot execute binary file
This is because the file is compressed, as indicated by the .xz
extension. You need to remove the compression before the file can be used.
这是因为文件被压缩,如.xz扩展名所示。您需要在使用该文件之前删除压缩。
xz -d ./run_me.sh.xz
chmod +x ./run_me.sh # probably not necessary if you already did that before
./run_me.sh
Other compression schemes like gzip
(.gz
extension), bzip2
(.bz2
extension) etc behave similarly; you just have to know the name of the command to uncompress it, which is of course usually easy to google.
其他压缩方案如gzip(.gz扩展名),bzip2(.bz2扩展名)等表现相似;你只需要知道解压缩它的命令的名称,这当然通常很容易谷歌。
#1
10
chmod -x
removes execution permission from a file. Do this:
chmod -x从文件中删除执行权限。做这个:
chmod +x path/to/mynewshell.sh
And run it with
并运行它
/path/to/mynewshell.sh
As the error report says, you script is not actually a script, it's a binary file.
正如错误报告所说,你的脚本实际上不是一个脚本,它是一个二进制文件。
#2
1
I was getting the same error running my shell script through a bash interpreter in PowerShell. I ran dos2unix myscript.sh
on the shell script, and now it runs ok.
我通过PowerShell中的bash解释器运行我的shell脚本时遇到了同样的错误。我在shell脚本上运行了dos2unix myscript.sh,现在运行正常。
#3
0
From a proposed duplicate:
从拟议的副本:
run_me.sh.xz: run_me.sh.xz: cannot execute binary file
This is because the file is compressed, as indicated by the .xz
extension. You need to remove the compression before the file can be used.
这是因为文件被压缩,如.xz扩展名所示。您需要在使用该文件之前删除压缩。
xz -d ./run_me.sh.xz
chmod +x ./run_me.sh # probably not necessary if you already did that before
./run_me.sh
Other compression schemes like gzip
(.gz
extension), bzip2
(.bz2
extension) etc behave similarly; you just have to know the name of the command to uncompress it, which is of course usually easy to google.
其他压缩方案如gzip(.gz扩展名),bzip2(.bz2扩展名)等表现相似;你只需要知道解压缩它的命令的名称,这当然通常很容易谷歌。