Walker News

Resolve Linux Shell Scripts Bad Interpreter Error

Due to different way of handling text file encoding, a Linux shell scripts might not working after transferring from one OS to another, in particularly from Windows to Linux.

For instance, an error message similar to “: Bad interpreter : no such file or directory” will pop up, if a shell scripts was written or backup in Windows Vista and later transfer to run on a Red Hat Linux machine.

So, it’s better to confirm the shell scripts will execute properly after file transfer (regardless of file transfer via scp, ftp, samba, shfs network drive, etc).

For some production shell scripts with dependencies (thus not possible to simply execute the shell scripts on ad-hoc basis), you can
 
  1. Make a copy of the shell scripts in question,
     
  2. Edit the the copy of shell scripts with your preferable editor (e.g. vi editor),
     
  3. Remove or remark all the lines EXCEPT the first line (i.e. the shebang) and execute it.

If you see the “: Bad interpreter : no such file or directory” error message,
  1. Confirm the shell scripts interpreter is exists or the path specified is valid.
    For example, if the shebang written as #!/bin/bash, execute either one of these common Linux commands to confirm the bash shell interpreter is exists in the /bin directory:
    • /bin/bash --version
    • file /bin/bash
    • ls -la /bin/bash

    If there is NO error message, the specified shell scripts interpreter is valid – then, the file encoding (next) might be the culprit.
     
  2. Run a dos2unix converter program to fix the text file encoding problem.
    So, suppose the shell scripts is called wsudo.sh, run this dos2unix command:

    You might need to backup the original file first before running dos2unix command

    dos2unix wsudo.sh

    Change the file permission mode to executable

    chmod 755 wsudo.sh

    and try to execute wsudo.sh again to confirm it works after the file encoding conversion.


Custom Search

  1. Using Linux od Command To View File In Bit – Walker News 21-09-07@00:12

    […] is to fix some Linux problems, e.g. compare files in binary form or bit level (i.e. 0 and 1), fix Bad Interpreter error message when executing Linux Bash shell scripts, […]

  2. Moshe 15-04-12@15:52

    Thanks!
    You saved my behind ;)

2017  •  Privacy Policy