27 Sep 2003 auspex   » (Journeyer)

Unix crack

Before I went to bed last night, I decided I should leave myself a note to try something later. I don't use a sticky note program or anything like that, and I figured I would miss a file containing the note. I decided to touch a note:

touch "Try blahblah for the blahblahblah"

That way, when I run ls, as I'm sure to do, I see my message.

But 'M' comes before 'T', so I was dissatisfied with the result. I renamed the file with a numeric prefix.

Then, I thought, "Why restrict myself to one line?" Indeed, I could insert newline characters in the filename, so I did so. But ls just showed question marks instead of newlines. A check of the man page revealed the --show-control-chars option. It worked, except for scatterring all the other filenames about. A wildcard fixed that easily enough.

So now I have these two (surely not portable) shell scripts, note and notes. The first takes a string argument and touches it with a little modification. The second lists, "showing" control characters, files matching those made by the first. Neither checks input or anything like that; I was about to fall asleep.

note

#!/bin/sh
touch ".^HNote from `date +"%-I:%M%P %A %e %B %Y"`
$1"
(That's '^H' the backspace character, not "^H" the string caret and 'H'.)

notes

#!/bin/sh
ls --show-control-chars .?Note*
(The '?' is a wildcard to catch the backspace.)

The backspace character rubs out the '.' which is there to keep normal ls clean. I sacrificed my initial purpose.

With a little modifcation, like using ui -in $USER, notes could include author information or whatever else. Of course, filename length is limited.

Well, for whatever reason, I only slept about two hours. I think I'll go back to bed now.

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!