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. :-)
Sunday, January 27, 2008
c++: animated process bar in c++
A process bar is useful to present the current processing status, here is my example:
void ProcessBar(int thisevt, int totalevt) {
if ( thisevt%1000 != 0 ) return ;
int totalc = 30;
int ic = (int)1.*totalc*thisevt/totalevt;
cout << "Status: [";
for (int a=0; a
cout << "=";
for (int b=0; b
cout << " ";
cout << "]";
printf("%6.2f%%", 100.*thisevt/totalevt);
//backspace
for(int a = 0; a <>
cout << "\b";
}
(of course, the code is specially for high energy physics analysis on event level, you could change it for timing etc...)
Friday, November 30, 2007
linux: how to merge/split pdf files
In linux, there is no professional acrobat avaible, which means that sometimes if you edit your pdf files, for example, merge, split pdf files, you may not have clue to do that. Lots of ppl in the net would recommend "pdftk" (pdf toolket) for you. I try to install, but some lib is needed. I have no time to install other dependent lib so I recalled I have a java tool: Multivalent. Just google it and find its page.
Usage:
java -classpath ~/Multivalent20060102.jar tool.pdf.Merge file1.pdf file2.pdf ...
That is it. You also can split your pdf file to separated ones. Of course, you need to download Multivalent20060102.jar from somewhere of the net. Yes, you can use "convert" to merge, but bad resolution and very slow, not recommended.
Wednesday, November 28, 2007
linux:how to download a whole site by wget
wget -r -p -np -k http://Your.Website.ToBeDownloaded.com
