Sunday, December 23, 2012

Development on C with Mac OS X 10.8

On times I tried to write some code on C. But unfortunately found out that I don't have any cc installed. The easiest way is to get them was simply install XCode from AppStore and I successfully did it.
Happy to continue, but wait, how should I compile? Still no any cc command.
The problem is that with XCode command line tools are not included into the distribution. Good that we can download these tools manually from Apple Developers Center section Downloads.
Package provides clang and gcc compilers and even gdb utility. More then enough for me.

Friday, December 21, 2012

Command not found

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/;
and in case of copying from *nix box to Windows one unix2dos.pl:
#!/usr/bin/perl -pi
s/\n/\r\n/;