calling dos2unix on shell script from within the script

I have a build script. It was created on Linux. For some reason, I got it to windows and modified it. And brought it back again to Linux.

Since there is the question of the ^M chars appearing, the way out is to do a dos2unix on the script file. This is done manually.

Is there a way to call dos2unix on the script from within the script itself ?

I tried the following:
The first line in the script was
dos2unix $0

The error I got was:
sh build.sh
: command not found
dos2unix: converting file build.sh to UNIX format ...
to UNIX format ...g file
dos2unix: problems converting file
: command not found
: command not found
'uild.sh: line 30: syntax error near unexpected token `
'uild.sh: line 30: `function o ()

Any pointers ?

Vino

You can call this script build.sh from another script say format.sh
and before executing the script do a dos2unix on build.sh

Encrypted,

Yes, that would work.

Still, if there anyway to do this.

Vino

Please check PATH in your build scripts.
Couple of 'command not founds' there.

what are u trying to do ?

is it not

dos2unix $1 ??

I have a build script. If dos2unix is not carried out on that script, then you get the errors that I had displayed.

I am trying to call dos2unix on the calling script. i.e. the one denoted by $0.

$1 refers to the first argument. No, I am not calling dos2unix on the first argument. Rather on the script which issued the dos2unix.