LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 05-23-2008, 12:59 AM   #1
Nergar
LQ Newbie
 
Registered: Feb 2007
Posts: 5

Rep: Reputation: 0
Question getopts fails if $1 isn't preceded by -


How can I catch $1 with getopts when it doesn't have a preceding - ? so I can run a script like this:

script directory [options]

Code:
foo /bar -f
without getopts failing?
 
Old 05-23-2008, 06:43 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 21,592
Blog Entries: 47

Rep: Reputation: 1408Reputation: 1408Reputation: 1408Reputation: 1408Reputation: 1408Reputation: 1408Reputation: 1408Reputation: 1408Reputation: 1408Reputation: 1408
Well, generally you shouldn't. If you use getopts you should use it properly, everything else is unexpected behaviour IMHO. Anyway, you could test for absence of switch sign, shift by one and then loop over the other variables.
 
  


Reply

Tags
args, bash, linux


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
question on getopts tostay2003 Programming 1 12-25-2007 04:39 AM
struggling with getopts mike9287 Programming 6 07-14-2006 12:42 AM
Mandatory arguments with getopts? rose_bud4201 Programming 2 03-10-2005 02:18 PM
getopts multiple parameters arnulfo Programming 2 12-23-2004 05:12 AM
Help with getopts command Rezon Programming 3 10-22-2003 04:12 PM


All times are GMT -5. The time now is 07:36 PM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration