SPUG:DOS textfiles and perl on unix

Brian Hatch spug at ifokr.org
Thu Mar 6 16:40:45 CST 2003



> DOS textfiles cause problems for unix, which tries to invoke
> /usr/bin/perl^M and subsequently fails with a helpful message.
> 
> ln -s /usr/bin/perl `echo -e "/usr/bin/perl\r"`
> 
> Actually lets the script run, in my limited testing with perl
> 5.8 on Mac OS X.  Another option would be to create a perl^M
> that issues a warning.
> 
> #!/bin/sh
> echo "error: $1 uses DOS linebreaks" >&2
> exit 1

You could also save the file without any DOS \r's at the end of
the line.  If you're FTPing, make sure you use ASCII mode.  If you
use SFTP (ftp-like over SSH) then there is no such beast, however
you can fix it once it's uploaded:

	$ cd /path/to/my/perl/script
	$ perl -pei.bak "s#\r#\n#g" my_perl_script

then my_perl_script won't have those annoying \r's and will run just
fine.  I had to create a cron job that did this in a CGI directory for
a client that constantly uploaded them from a DOS machine.

Rather than hacking around to let a broken program work, fix the
program.


--
Brian Hatch                  "It will be fun. Assuming you are not
   Systems and                vaporised, dissected, or otherwise
   Security Engineer          killed in an assortment of supremely
http://www.ifokr.org/bri/     horrible and painful ways.
                              *Exciting*, isn't it?"
Every message PGP signed
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.pm.org/pipermail/spug-list/attachments/20030306/4768340c/attachment.bin


More information about the spug-list mailing list