Text Link Ads

Thursday, September 13, 2007

Tip for the day: BOURNE SHELL PSEUDO HASH TABLES

The best way to explain this is with an example:

You may want to write a simple script that launches an xterm window with different color
options. Pseudo hash tables in bourne shell.

$ xwindow MidnightBlue

An easy way to this is by first listing the supported colors in the script (pseudo hash table):

DarkSlateGrey="#2f4f4f"
DimGrey="#696969"
MidnightBlue="#191970"
NavyBlue="#000080"

Next, simply grab the hex color code by using the following command:

BGColor=`eval echo $"$(echo $1)"`

"$(echo $1)" evaluates to "MidnightBlue" and
`eval echo $MidnightBlue evaluates to "#191970".

Simply launch the xterm window using $BGColor as the background color:

xterm -bg="$BGColor" &

This method for extracting pseudo hash values may be used for NIS map files, file date stamps, GUI colors, etc.

No comments: