LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-09-2014, 02:56 PM   #1
nyc_rr
LQ Newbie
 
Registered: May 2014
Distribution: Linux Mint 16 Petra
Posts: 26

Rep: Reputation: 25
Can bash's getopts function handle switches as words?


Hello friends

I've written some bash scripts that uses switches with the bash's built-in getopts function. But the switches I am currently using are single letters types. Is it possible to use words with getopts to my bash scripts?

For example instead of using a switch this way

myscript -o filename

I want to use a word switch like so

myscript -out filename


Thanks

Last edited by nyc_rr; 06-09-2014 at 02:57 PM.
 
Old 06-09-2014, 03:16 PM   #2
nyc_rr
LQ Newbie
 
Registered: May 2014
Distribution: Linux Mint 16 Petra
Posts: 26

Original Poster
Rep: Reputation: 25
After searching the net, I found out the built-in getopts function is limited to only single characters. However I read there are two external commands called getopt and getoptlong that handle word switches but is a little more cumbersome to use.

So, I guess I'll stick to bash's built-in getopts function instead.
 
Old 06-09-2014, 08:51 PM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
See if this can give you some options (pardon the pun):- http://www.linuxquestions.org/questi...andling-34675/
 
Old 06-10-2014, 02:07 PM   #4
nyc_rr
LQ Newbie
 
Registered: May 2014
Distribution: Linux Mint 16 Petra
Posts: 26

Original Poster
Rep: Reputation: 25
Thanks grail for the link. I will study the code and see if it's for me. I agree with the author of that post, the long word option route is quirky and cryptic

Last edited by nyc_rr; 06-10-2014 at 02:21 PM.
 
  


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
Nagios: how to handle transparent switches /dev/me Linux - Networking 10 02-03-2010 11:09 PM
how to handle errors/notifications on scripts? richikiki Slackware 3 07-19-2006 03:57 AM
how to handle errors/notifications on scripts? richikiki Programming 1 07-19-2006 01:09 AM
I am unable to handle some website scripts on my Linux server MandrivaUser Linux - Software 1 02-01-2006 09:55 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:59 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