How to identify whether the script is in Unix format or not ?

Hi All,
I have the below scenario in my environment
Developers used to copy file from windows to Linux box. Some time on the copied file developers miss to run the dos2unix utility. Because of this script gets failed during the execution. Most of the failures are due to the dos2unix format issue.

Is there any way to identify if the script is not in a UNIX format ?

Hi

The file command will help you in this.

a is a unix file

$ file a
a: ASCII text

b is a file containing the ctrl-M characters at the end.

$ file b
b: ASCII text, with CRLF line terminators

Guru.

Thanks Guru..

I transfered a script from windows to unix and tried the file command.

But when i try to execute got the below error.

use dos2unix command

Yes, i agree dos2unix will convert the file from dos to UNIX format. But i want to execute dos2unix only if the file is not in UNIX format.

Hi

You can do something like this.

THe file 'file1' has the Ctrl-M character in every line:

$ cat -v file1
#!/usr/bin/bash^M
echo welcome^M

You can check for the count of ctrl-M characters :

$ grep -c '^M$' file1
2

Note: ^M = Ctrl-V + Ctrl-M

@kalpeer: See if this link helps.

I got the answer from the below post. Thanks everyone