Archive for February, 2010

A while back I assembled the following shell tips and tricks notes for an ad-hoc ‘lunch and learn’ session at work. For some reason (probably for colour) I had made these notes in microsoft word instead of plain text. That made them of limited use for reference, not being cut and pastable (since word mucks up the quote characters). Despite a few things that are work centric (references to clearcase and our source code repository directory structure), there’s enough here that is generally applicable that the converted-to-text version makes sense to have available as a blog post.

Variables

You will have many predefined variables when you login. Examples could include

$HOME home dir.
$EDITOR preferred editor.
$VISUAL preferred editor.
$REPLYTO where mail should be addressed from.
$PS1 What you want your shell prompt to look like.
$TMPDIR Good to set to avoid getting hit as badly when /tmp fills up.
$CDPATH good for build tree paths.

$CDPATH good for build tree paths. Example: CDPATH=.:..:/home/hotelz/peeterj:/vbs/engn:/vbs/test/fvt/standalone:/vbs/common:/vbs/common/osse/core ; one can run: 'cd sqo' and go right to that component dir.
$1 First argument passed to a shell script (or shell function).
$2
$* All arguments that were passed to a shell script

Wildcards

All files starting with an 'a', and ending with a 'b'

# ls a*b

All files of the form 'a'{char}'b'

# ls a?b

Quotes

Three different kinds. This is one of the most important things to know for any "shell programming".

Single quotes

Variables and wildcards are NOT expanded when contained in a set of single quotes. Example:

Double quotes

You don't have to double quote something for this sort of wildcard, and variable expansion, so you could write:

# echo $a $b

and the result will be the same:

foo goo boo

There is a difference though, namely, echo will treat this as three arguments, because the command is expanded before the final execution. This can be important when you want something with spaces to be treated as a single argument. Example:

The alternate syntax can be useful if you wanted to run a command inside of a command.

Other Special Shell Characters

~ your home dir.
; command separator
\ backslash (escape). When you want to use a special character as is, you either have to single quote it, or use an escape character to let the shell know what you want.

The for loop.

If you have the quotes and variables mastered, this is probably the next most useful construct for ad-hoc command line stuff. We use computers for repetitive stuff, but it's amazing how little people sometimes take advantage of this.

By example:

# for i in `grep : /tmp/something` ; do echo $i ; done

Here, i is the variable you name, and you can reference it in the loop as $i.

What's notable here is not the perl itself, but the fact that to run some of these commands required passing a pile of shell special characters. In order to pass these all to perl unaltered, it was required to use single quotes, and not double quotes.

Common to grep, sed, and perl is a concept called a regular expression (or regex). This is an extremely valuable thing to get to know well if you do any programming, since there's often a lot of text manipulation required as a programmer. Going into detail on this topic will require it's own time.

Shell Aliases

These are one liner "shortcuts". ksh/bash example:

alias la='ls -a'

Shell Functions

Multiline shortcuts. ksh/bash example:

function foo
{
echo boo
echo foo
}

This is similar to putting the commands in their own file and running that as a script, and can be used as helper functions in other scripts or as more complex "alias"es.

calling this with ddda 0 will attach the ddd debugger to the db2sysc process db2pd reports to be node 0.

Except for the perl fragment, which is basically a combined 'grep' and 'sed', this example uses many of the things that have been explained above (variables, embedded command, single quotes to avoid expansion and for grouping arguments).

The two or three people that read this blog may have noticed that it has degenerated into a mess of bad poetry and strange bits of writing, recipes, and even a flammable posts commenting on how graphic porn has gotten since last purchasing a such a mag over 15 years ago (that post I deleted since the masturbatory references so close to all the math and physics was just too strange).

The reasons for this sudden deviation from my old weird blogging norm of perl, math, and physics, is that after 11 years, my marriage suddenly and unexpectedly dissolved. Things are all very confused right now, but I’ll eventually get my life under control again.

I’m going to restore this blog to its old norm of obscurity, and when or if I do feel inclined to post personal entropy I’ll do it on the blogger blog I’d created once and never really used (since it didn’t handle math typesetting in a natural way like on wordpress).

I thought I was doing pretty well with a read of this book, having found typos on page 15, where the index variables got mixed up, leading to something that was obviously wrong. However, after not too much further I get bogged down when he starts referring to use of contact transformations. These are used to develop a systematic way to arrive at the quantum mechanical equations that correspond to a classical action principle (perhaps without even a Hamiltonian). So, I’ve got to shelf this book for a while and go study some more of Goldstein, who appears to cover this topic under the guise of Canonical transformations. I’d seen that chapter and skipped it, not having any idea where it was really headed or why I’d want to study it (like a lot of Goldstein, which at least in the first edition is all too terse). Now I know some of the point of it all, and I expect this will make the study of it go more smoothly.

I also have to say that Feynman is pretty causal with his algebra. I’ve blundered around with trying to reproduce his equation (28), which “This can be expressed in other ways” produces. I got (27) after some messy manipulations, but a hint about how to get to (28) would be nice. Trying again with fresh eyes may help. I’d say that’s a problem for another day.

Dice up the shrooms, and fry em. Add a bit of white wine to help them get soggy, and fry till the wine evaporates.

Dice up the pepper. Small enough that the kids and wife won’t try to pick em out.

Cut zuke into smallish pieces, and fry em up too (separate from the mushrooms since they cook at separate speeds).

Fry up the ground beef. If frozen make sure to take it out of the freezer in the morning (if cooking mid afternoon). Breaking it up right at the beginning is helpful so it doesn’t clump.

Now’s a good time to get the noodles cooking.

Combine the meat, the peppers, the mushrooms, and the sauce in a big pan, and mix em and cook em a bit all together.

Michelle says I should have fried the spinach a bit to make it floppy. Try that next time. That would also make it easier to add it to the layers, because it makes the layers all wobbly when putting it on raw.

Bottom layer
– noodles on the bottom, slightly overlapping
– cottage cheese, then mozzarella, then sauce, then some spinach.

2nd layer
– same thing

top layer

– noodles, mozzarella, then grate on the parmesan. Cover with foil and cook at 375 (having preheated oven), then 5-10 more minutes uncovered. I’m not sure if the foil makes a difference and I’m going to try next time without it.