-bash: ./stweak100_2.sh: /bin/bash^M: bad interpreter: No such file or directory

Posted by

As an admin when you run different scripts and get this error, basically you will need to change or convert the script, probably the type format of the script is for Windows OS and need to be converted to allow the execution on Unix/Linux environments, sometimes it happens otherwise.

You can do it two ways,

1. Notepad++

You can use notepad ++ to change the format of the file, use the following steps.

> Open Notepad ++
> Load the script
> Go to Edit
> EOL Conversion
> You can check on the bottom of the file the type format of the script. (check following screenshot)
> Select UNIX/OSX Format
> Save file
> Close

Screen Shot 2019-02-21 at 15.16.21
Notepad ++ EOL Conversion

Note: If the script is for UNIX/Linux and need to be executed on Windows OS, use the “Windows Format” option.

2. dos2unix

Also, dos2unix is a Linux tool that allow you to convert the file format of the script, to be executed on Windows OS or UNIX/Linux environments. If you need to convert to be executed on Windows please check unix2dos.

Only need to use the command like the following example,

*******
[root@localhost github]# ./stweak100_2.sh
-bash: ./stweak100_2.sh: /bin/bash^M: bad interpreter: No such file or directory
[root@localhost github]#

*******
[root@localhost github]# dos2unix stweak100_2.sh stweak100_2_UNIX.sh
dos2unix: converting file stweak100_2.sh to Unix format …
dos2unix: stweak100_2_UNIX.sh: No such file or directory
dos2unix: Skipping stweak100_2_UNIX.sh, not a regular file.
*******

If you see something like the previous example, it worked, now run the script and you will not get the initial error.

“-bash: ./stweak100_2.sh: /bin/bash^M: bad interpreter: No such file or directory”

For more information, use man pages.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s