CHANDRAN SUBRAMANIAM - INFINEON MALACCA

The Star  |  Metro  |  Murasu  |  FACEBOOK  |  Friendster  |  Yahoo Mail  |  Gmail  |  KWSP  |  Melaka Hari Ini
 

Unix ...

Why Use Shells

Well, most likely because the are a simple way to string together a bunch of UNIX commands for execution at any time without the need for prior compilation. Also because its generally fast to get a script going. Not forgetting the ease with which other scripters can read the code and understand what is happening. Lastly, they are generally completely portable across the whole UNIX world, as long as they have been written to a common standard.

One of the major weaknesses in many shell scripts is lines such as:

cat /tmp/myfile | grep "mystring"

which would run much faster as:

grep "mystring" /tmp/myfile

Suppose you want to match a specific number of repetitions of a pattern A good example is phone numbers. You could search for a 7 digit
phone number like this:

grep "[[:digit:]]\{3\}[ -]\?[[:digit:]]\{4\}" file