Sometimes we wrote a script intended for linux but we are using windows. However, when we deploy the script to linux it doesn't work.

For example you've created the file helloworld.sh in windows with the following content:

#!/bin/sh
echo "Hello World"

Transport helloworld.sh to linux and make it executable (i.e. using the command chmod 755 helloworld.sh). Execute it using the following command:

./helloworld.sh

Expect to see something similar to the following error:

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

To remedy this, run dos2unix command with helloworld.sh as follows:

dos2unix helloworld.sh

Expect an output similar to the following:

dos2unix: converting file helloworld.sh to Unix format...

After this, execute the helloworld.sh again and expect no error.