LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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, 01: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-07-2012, 11:33 PM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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-07-2012 at 11:34 PM. Reason: comprehensibility
 
1 members found this post helpful.
  


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:02 AM.

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
Open Source Consulting | Domain Registration