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

前端 未结 5 962
执笔经年
执笔经年 2020-12-16 03:17

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/myn         


        
相关标签:
5条回答
  • 2020-12-16 04:03

    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.

    0 讨论(0)
  • 2020-12-16 04:09

    That script is simply not a shell script. A shell script is usually readable and contains shell code. The output your cat command shows looks indeed like it's a binary of some sort. As some note, it might be because of a file conversion issue when copying but it looks more like an actual binary to me.

    You can check what it is identified as with the file command so:

    file path/to/mynewshell.sh
    

    Just start with a clean script and rewrite the code, it looks like you just want to run some R scripts in a directory?

    Make sure the R scripts point to the right R script executioner.

    0 讨论(0)
  • 2020-12-16 04:11

    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 -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.

    0 讨论(0)
  • 2020-12-16 04:17

    To anyone else having the problem i had.

    i was trying to run a 16 bit unicode text file converted to a shell script, this doesn't work as all 16 bit unicode text files have a 0xFFFE marker at the start making mac os not like the file and this gives the “cannot execute binary file” error.

    open the text file click on "Format" at the top, go down to "Make Plain Text" click it.

    open your terminal type chmod 777 /path/to/file.sh

    put in terminal: /path/to/file.sh to run it

    0 讨论(0)
  • 2020-12-16 04:21

    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.

    0 讨论(0)
提交回复
热议问题