I'm stuck with a wired problem.My bash scripts are not working now.It worked previously.I don't know why.Interestingly the commands on the script work when I enter it directly on the terminal.

This a sample line from my script ls

On the terminal when I run sh ./check.sh, the output is : command not found ls

The output is similar for other commands also,except echo for which is showing the correct output.

I request every kind people to help me.


You have created the script with a DOS (windows) editor, that's added a \r (carriage return) to the end of every line.

You can convert the file with:

dos2unix check.sh check.sh.tmp && mv check.sh.tmp check.sh

I personally usually do vim check.sh and then :set notx and then save the file: :wq

  • I don't have dos2unix installed Ic choose the second vim method.Thank You So much.. – lalthomas Sep 19 '14 at 5:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.