Browsing All Posts published on »May, 2009«

Use lassign to Assign Command-Line Parameters to Variables

May 28, 2009

0

The Problem You need to assign command-line parameters to variables. For example: set [lindex $argv 0] server set [lindex $argv 1] port set [lindex $argv 2] user set [lindex $argv 3] password The problem with this approach is it takes lots of typing. Cut and paste can help reducing some of it, but it is […]

Tcl: Use commandloop to Provide Interactive Access to Your Procedures

May 14, 2009

0

When I wrote text base programs in high-level programming languages, I often need to create a simple menu, get the user’s choice, then dispatch the appropriate procedure. The dispatch code often include lengthy swich (case) statement: switch (choice) { case 'a': function_a(); break; case 'b': function_b(); break; } ... This design pattern was fine if […]

Debugging Tcl Script with commandloop

May 12, 2009

0

Besides using puts to debug my Tcl script, I also like this technique, which set up a break point within my script. There are times when I cannot use that technique, I use the commandloop command to create an impromptu break point. Before we get started, let me clarify that the purpose of commandloop is […]

Use for_file to Ease Line-by-Line Processing

May 12, 2009

2

In my job, I often need to open a file, read and process each line until the end. In Tcl, that pattern can be translated as: set infile [open file.txt r] while {[gets $infile line] >= 0} { # do something with $line... } close $infile Simple? Yes, but I can still see room for […]

Display Weather from Command Line

May 8, 2009

0

Since I work on Linux/OSX command line all day, I prefer to get my information such as stock quote or weather via command line. Here is a script to do that. A couple of notes: I use curl instead of the TclCurl package because my system does not come with TclCurl The script employs Google […]

View Stock Price Using Command Line

May 6, 2009

2

I live on command line all day, so it is convenience to perform many tasks using the command line. One of those is to check stock price: curl -s 'http://download.finance.yahoo.com/d/quotes.csv?s=csco&f=l1' The above command check for the last price (with some delay) of Cisco Systems. If you want to check the price for other tickers, replace […]

Locate a File and Go to It

May 4, 2009

0

I often need to find a file, then cd to its directory. This command will do both, provide that the file’s name is unique enough: $ cd $(dirname $(find ~ -name emails.txt)) Please note that the above command works for bash shell, but not csh: csh’s equivalent to the $( … ) construct is the […]

Follow

Get every new post delivered to your Inbox.

Join 34 other followers