A simple example is here:
http://tldp.org/LDP/abs/html/extmisc.html#EX33A
From http://www.tomshardware.com/ucg/commands/getopt-15186.html
getopt
UNIX Shell: Shells (ash, bash, bsh, csh, ksh, sh, tcsh, zsh)
Function
Cleans up and checks options given to a shell script. It split option given together and place each option in its own variable. Any additional arguments is placed after --
Syntax
set -- `getopt optstring $*`
getopt optstring parameter
Linux: [ options... ] -- optstring parameter
Linux: getopt [ options... ] -o optstring [ options... ] [ -- ] parame
optstring Specifies a string of option letters that is recognized by the script.
NOTE: If a letter is followed by a colon (:) it will take an argument.
parameter Specifies the options to check. (This is often $*, the argument list to the script).
set -- Sets the argument list $* .
Linux:
-a Allows long options to start with a single -.
-h Shows help information.
-l longoptions Specifies a long option that will be recognized.
-n progname Specifies a program to use to report errors
-o optstring Specifies a list of short options.
-q Disables error reporting
-Q Doesn't generate any output. Errors are reported unless -q is also given.
-s shell Uses quoting conversions of the specified shell (sh, bash, csh or tcsh)
-u Doesn't quote the output.
-T Will test if this is the enhanced version.
-V Shows version information.
File Name: getopt Directory: /usr/bin/ Type: External
Note:
This is very useful to make easy option check in a shell script.
set -- `getopt ab:c $*`
Specifies that a and c don't take an argument but c will.
If argument is: -ac -b hello
It will be converted to: -a -c -b hello --
If argument is: -bhello ucg
It will be converted to: -b hello -- ucg
set -- `getopt -l help ab:c $*`
Also recognizes the long option --help
Tuesday, February 26, 2008
Linux: command: how to use getopt
Monday, February 25, 2008
Linux:command: sort
'sort' in linux is sometimes very usefult. For example, I have a file like this:
pt 2.9
eta 3.0
phi 4.5
px 2.1
If you want to rank those variables due to the increasing order of the 2nd column, then you can use 'sort -n -k2 yourfile.txt'. '-k2' means the position of the key is the 2nd.
Sunday, February 17, 2008
Wednesday, February 13, 2008
Linux: X server crashes
Long time ago, I have a problem that my X server crashed when I change my current profile from one network profile in net applet. I had no clue at all then. I remember that I changed .gnome and some directories, then the problem is gone. But I have to use kde then. Today I logon gnome and X server crashed again. I cannot fix it by upgrading using installation disk. And I create a new account, it is working well. And I searched the internet and realized that some people also have the same problem with me. Actually the problem is from 3D effect. I have to edit the file: /etc/X11/xorg.conf to comment two lines which is bad for x server. They are:
Option "Composite"
Option "XaaNoOffscreenPixmaps" "1"
After removal, I can restart X server. :-)