LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 01-04-2007, 01:33 PM   #1
johngreenwood
Member
 
Registered: Nov 2006
Location: Lancashire, United Kingdom
Distribution: Slackware 13
Posts: 243

Rep: Reputation: 31
bash script: making options?


Hi, I'm not sure whether this is the correct place to post this, but here goes. I'm learning how to write bash scripts and I was wondering how to make a script so it could have different options, you know, like rm -rv or cp -v. I have written a simple script and want to make it so I can pass these options to it when run. So far I have it so it checks if there is an argument, and if there is it prints the help screen and exits, I could type: command -I -like -tabasco -sauce, and I get the help screen. But I would like to be able to add more options to it. So could someone kindly explain to me how this is done, or point me in the right direction, any help at all would be excellent.

Thanks

John
 
Old 01-04-2007, 01:41 PM   #2
MicahCarrick
Member
 
Registered: Jul 2004
Distribution: Fedora
Posts: 241

Rep: Reputation: 31
Check out the Advanced Bash-Scripting Guide.

- Micah
 
Old 01-04-2007, 01:45 PM   #3
johngreenwood
Member
 
Registered: Nov 2006
Location: Lancashire, United Kingdom
Distribution: Slackware 13
Posts: 243

Original Poster
Rep: Reputation: 31
I spent about two hours looking on there today, could you please tell me which part I should be looking at. After the two hours I got bored and did stupid stuff, like have a script ask me if I wanted to be root, and say something stupid to me after I say yes.

Thanks

edit - damn, never mind, after clicking the link I saw it in two seconds. I can't believe I missed it.

Thanks very much MicahCarrick

John

Last edited by johngreenwood; 01-04-2007 at 01:47 PM.
 
Old 01-04-2007, 01:53 PM   #4
MicahCarrick
Member
 
Registered: Jul 2004
Distribution: Fedora
Posts: 241

Rep: Reputation: 31
Sure. And for other people reading this post, Using getopts to read the options/arguments passed to a script.
 
Old 01-04-2007, 01:55 PM   #5
johngreenwood
Member
 
Registered: Nov 2006
Location: Lancashire, United Kingdom
Distribution: Slackware 13
Posts: 243

Original Poster
Rep: Reputation: 31
hehe, once again, thanks, I love this place.
 
  


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
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 6 03-21-2013 10:35 AM
Bash: how to handle --options? humbletech99 Programming 4 10-07-2011 07:21 AM
making a bash script file Berticus Linux - General 1 10-15-2005 11:14 PM
making select show its menu in a bash script? zidane_tribal Programming 6 05-02-2005 05:52 AM
making a bash script student04 Linux - Software 5 01-11-2005 03:41 AM


All times are GMT -5. The time now is 09:13 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 Google+: linuxquestions
Open Source Consulting | Domain Registration