home *** CD-ROM | disk | FTP | other *** search
/ ftp.ncftp.com / ftp.ncftp.com.zip / ftp.ncftp.com / ncftp / older_versions / ncftp-3.2.2-src.tar.bz2 / ncftp-3.2.2-src.tar / ncftp-3.2.2 / sh / unix2dos.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  2001-12-14  |  685b  |  34 lines

  1. #!/bin/sh
  2.  
  3. add_ctrlZ=0
  4.  
  5. es=1
  6. if [ $# -eq 0 ] ; then
  7.     exec awk '{ printf("%s\r\n", $0);} END { if (Z == "1") printf("%s", "\032");}' "Z=$add_ctrlZ"
  8. elif [ ! -f "$1" ] ; then
  9.     echo "Not found: $1" 1>&2
  10. else
  11.     for f in "$@" ; do
  12.         if awk '{ printf("%s\r\n", $0);} END { if (Z == "1") printf("%s", "\032");}' "Z=$add_ctrlZ" < "$f" > "$f.tmp" ; then
  13.             if cmp "$f" "$f.tmp" > /dev/null ; then
  14.                 rm -f "$f.tmp"
  15.             else
  16.                 touch -r "$f" "$f.tmp"
  17.                 if mv "$f" "$f.bak" ; then
  18.                     if mv "$f.tmp" "$f" ; then
  19.                         rm -f "$f.bak"
  20.                         es=$?
  21.                         echo "  converted $f"
  22.                     else
  23.                         rm -f "$f.tmp"
  24.                     fi
  25.                 else
  26.                     rm -f "$f.tmp"
  27.                 fi
  28.             fi
  29.         else
  30.             rm -f "$f.tmp"
  31.         fi
  32.     done
  33. fi
  34.