Saturday, October 2, 2010

Script written in Win is not working in *nix environment?

Have you ever copied a bash or any other script written your favorite windows editor to UNIX environment and saw it does not work?

Yeah? Well its a Line terminator issue between windows and Linux environment. The enter key, in windows appends a CR and LF code into the end of the line; where in *nix only CR is appended at the end of the line.

Check the script with cat -v, if it display something ^M at the end of the line, that means this text file was created under windows environment. And CR LF is causing the execution of bash script to fail.


$cat -v WonderScript.sh

Once identified, this issue can easily be fixed with the dos2unix command.

$dos2unix WonderScript.sh
$chmod +x WonderScript.sh
$./WonderScript.sh

That's it !!

Cheers!
DEBU




No comments:

Post a Comment

AWS re:Invent summary 2017

As you might know, this year’s AWS re:Invent was held @ Las Vegas 11/27 – 12/1.   Below links could be a good start to explore all ...