PDA

View Full Version : Shell Scripting: How to parse arguments passed to the script



jucas_lo
March 1st, 2009, 04:41 PM
Hi!

I'm new to bash scripts, and I wanted to know how to parse arguments in a script, in the same way as the command line tools in linux do.

For example when you use find, and you wanna find files with a particular name, then you do "find -name somename".

I was wondering if there is a standard way to do that on a bash script, or if you just parse the arguments manually....

Also i would like to have long and short forms for my scripts options (such as -h or --help for a help option)

I'd appreciate any help or comment from you guys!

thank you very much!!!!

:guitar:

dwhitney67
March 1st, 2009, 04:43 PM
Use getopt.

Reference the man-page for more details.

jimi_hendrix
March 1st, 2009, 04:53 PM
use getopt.

Reference the man-page for more details.

+1

jucas_lo
March 1st, 2009, 10:35 PM
Thanks guys that was exactly what I was looking for.