Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

linux

bash

shell

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.

like image 926
R Bud Avatar asked May 22 '16 18:05

R Bud


1 Answers

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.

like image 93
Jahid Avatar answered Sep 28 '22 21:09

Jahid