Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 03-07-2012, 01:04 AM   #1
LQ Newbie
Registered: Jul 2010
Posts: 22

Rep: Reputation: 0
use getopt in shell script

I want to use getopt(1) to check the shell script's option and its' option arguments!
e.g. --version|-V --update {a | b}
when i type: --up
it should prompt that it can not recognize --up this option, other than lack of option arguments --update
it should prompt that it lacks of option arguments
i wrote this shell script:


ARGS=`getopt -o ab:c:: -l a-long,b-long:,c-long:: -- "$@"`

but, when i input:
./ --b-lo
it prompts that the --b-lo lacks of arguments, other than it can not recognize it
Old 03-07-2012, 11:33 PM   #2
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,577
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
The error message from ./ --b-lo is correct. --b-lo is an "unambiguous abbreviation" of the --b-long defined in your getopt command as requiring an option argument which is not present in ./ --b-lo

Last edited by catkin; 03-07-2012 at 11:34 PM. Reason: comprehensibility
1 members found this post helpful.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to pass command line arguments from one shell script to another shell script VijayaRaghavanLakshman Linux - Newbie 5 01-20-2012 09:12 PM
BASH script using getopt to parse optional arguments nano2 General 6 04-28-2011 08:09 AM
shell script: can getopt process more than one argument per option? BrianK Programming 2 12-13-2007 05:11 PM
need help with getopt in a shell script BrianK Programming 3 06-18-2004 12:36 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:34 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration