Write Only Code

9 PM January 21, 2004

This line of code took me half an hour to write and test. (Broken into multiple lines for readability.)

echo \\t-ps -ef '|' 
   awk \'$$''$$\1 = \"$${LOGNAME}\"
        \&\& /`basename $${exe}`/ \&\& !/awk/ 
            {print $$''$$\2}\' '|'
   xargs -n 1 kill -9 >> ${MAKE_DEPEND}; 

This code is part of a makefile action that outputs a makefile rule. This particular line causes the output rule to kill a running executable, prior to linking it. I wrote it because I was sick of getting 'Text file busy' errors, and having to restart the make.

I am particularly proud of the $$''$$ bit. That is how to output two consecutive dollar signs into the generated make rule. $$$$ must be some kind of reserved symbol in our ancient version of make, because it causes a five digit number to be output.

By alang | # | Comments (2)
(Posted to Software Development)

Comments

At 11:28, 22 Jan 2004 Chris Johnsen wrote:

Make will translate $$$$ from the Makefile into just $$ on the command line. Just as a shell sees $FOO as a request for the the value of the variable named 'FOO', it sees $$ as a request for the value of the variable named '$'. Most UNIX shells put the PID of the shell in this variable.

So, it is the shell that is generating this five digit number (its own PID), not make.

(#)
At 19:17, 22 Jan 2004 Alan Green wrote:

Yep - that sounds right.

(#)

Add Comment




(Not displayed)






(Leave blank line between paragraphs. URLs converted to links. HTML stripped. Indented source code will be formatted with <pre> tags.)




© 2003-2006 Alan Green