LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


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

Rep: Reputation: 0
use getopt in shell script


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

#!/bin/bash

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


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

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
The error message from ./test.sh --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 ./test.sh --b-lo

Last edited by catkin; 03-08-2012 at 12:34 AM. Reason: comprehensibility
 
1 members found this post helpful.
  


Reply


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 10:12 PM
BASH script using getopt to parse optional arguments nano2 General 6 04-28-2011 09:09 AM
shell script: can getopt process more than one argument per option? BrianK Programming 2 12-13-2007 06:11 PM
need help with getopt in a shell script BrianK Programming 3 06-18-2004 01:36 PM


All times are GMT -5. The time now is 12:51 PM.

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