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

RCA - Root Cause Analysis

An important step in finding the root causes of issues or occurrences that happen within a system or organization is root cause analysis (RC...