Once on running one of my bash scripts I simply received
: command not found
without specifying illegal line or any useful information.
Script was fully valid and I was more then sure that it has to work.
The problem was
not very obvious. Scripts were deployed from Windows machine and the only idea was if somehow symbol codes where changed. I know that there is a little difference in ASCII text between Windows and Linux and it's new line symbols. On the first one they are 0d0a (\r\n) when on *nix - simple \n. After running
hexdump I found that Windows line breaks are there.
It seams like bash doesn't like these symbols, so I tried to get rid of them.
First I used
iconv but it didn't help. I still received the same error.
So I googled and found
this page
.
dos2unix was excellent for me. So I added
find "${deploy.dir}" -name *.sh -exec dos2unix -ko {} \;
to my deployment script and didn't have problems with this anymore.
What about second solution? Now I have additional perl scripts in case if
dos2unix won't be available on hosts.
dos2unix.pl:
#!/usr/bin/perl -pi
s/\r\n/\n/;
an
d in case of copying from *nix box to Windows one
unix2dos.pl:
#!/usr/bin/perl -pi
s/\n/\r\n/;