I'm probably late for this one, but I had the same problem and didn't want to put the special character ^M in my script (I worry that some editors might not display special ones or some later programmer might replace it with two normal characters: ^ and M ...).
The solution I found passes a special character to grep, allowing the shell to convert its hex value:
if head -1 ${filename} | grep $'[\x0D]' >/dev/null then echo "Win" else echo "Unix" fi
Unfortunately, I cannot make the $'[\x0D]' construct in ksh. In ksh, I found the following: if head -1 $ {filename} | od -x | grep '0d0a $'> / dev / null then echo "win" yet echo "unix" c
od -x displays text in hexadecimal codes. '0d0a$' is the hexadecimal code for CR-LF (DOS-Win line terminator). Unix line terminator has the value '0a00$'
source share