Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

bash - "cannot execute binary file" when trying to run a shell script on linux

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

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.

1.The result of cat -v path/to/mynewshell.sh is: ^@^@^@^@^@^@^@^@Rscript "$dir"/diver_script.R done

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.When i ran file path/to/mynewshell.sh : i got this "Bourne-Again shell script text executable"

Please give any advice on how I can try executing the shellscript.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

chmod -x removes execution permission from a file. Do this:

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...