Twitter Updates

    follow me on Twitter

    G-AVLN in front of her home

    G-AVLN in front of her home

    Mostly Unix and Linux topics. But flying might get a mention too.

    Thursday, July 21, 2005

    Counting patterns in KSH

    I was explaining the pattern matching in the shell earlier today, and used a very unfortunate example for explaining the "exactly one" pattern:

    if [[ $var == @([0-9])% ]]; then...

    I have (correctly) explained the above pattern as exactly one digit followed by a percent sign. One of the delegates asked me: why use the fancy characters? Wouldn't the following:

    if [[ $var == [0-9]% ]]; then...

    be the same? And if so, what's the point of the additional characters! Got me going for a moment! The answer is in the poorly chosen example. Although it works, one would never use the 'exact one' counting in relation to a single pattern specification.

    The @(...) notation is used when you need to 'count' alternative patterns, as in:

    if [[ $var == @(+|-)[0-9] ]]; then...

    Without the @ character, the brackets needed for enveloping the alternative patterns would not work:

    if [[ $var == (+|-)[0-9] ]]; then...
    ksh: syntax error: '==' missing second argument

    And without the brackets altogether:
    if [[ $var == +|-[0-9] ]]; then...

    gives:
    ksh: syntax error: '|' unexpected operator/operand

    Wednesday, July 20, 2005

    Bootable Knoppix

    I'm teaching the shell scripting course, and as usual I'm being asked if we have access to the Internet.

    We normally don't allow the Internet in the classroom (unless it is needed for the course, of course). We just need to take away a temptation of browsing the net in the middle of a session, as we (the lecturers) are a vain lot, and can take such behaviour personally ;-)

    Now, however, my approach has changed! This week, having asked Del to connect the class to the net, instead sending the deles to our Internet cafe's, I told them to reboot their boxes from the Knoppix CD, and use it for e-mail at breaks or lunch. The process of rebooting the machines is short enough to make it viable, but long enough to stop them from abusing it.

    That means the best of both worlds! No interruption during lectures, yet they can access their e-mail. Will be recommending this method to our MS-Windows lecturers ;-))

    Blog Archive