#! /bin/sh for j in "$@" do # convert file only if command file says: # ... with CRLF line terminators ftype='' ftype=$(LANG=C /usr/bin/file "${j}" 2>/dev/null) echo ${ftype} | grep -q 'with CRLF line terminators' is_dos=${?} if [ "${is_dos}" -eq "0" ] then /usr/bin/sed 's/ *$//g' < "${j}" > /tmp/$$ # strip CRs at end of lines cp /tmp/$$ "${j}" # cp to keep perms, e.g. x-bit rm /tmp/$$ fi done