LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 07-01-2010, 06:16 AM   #1
izghitu
Member
 
Registered: Oct 2005
Location: localhost.localdomain
Distribution: CentOS
Posts: 108

Rep: Reputation: 16
bash command line arguments


Hi,

I want to make a script that can take command line arguments and run like this:
./script --domain=domain.com --path=/path --alias=alias1 --alias=alias2 --alias=aliasN

Is there any howto on how to do this or are there any docs? I am not sure what to google for and when I search for bash command line arguments I get docs about other style command line arguments that are of no use for me

Please help

Thanks
 
Old 07-01-2010, 06:35 AM   #2
subho.d
Member
 
Registered: Jun 2010
Location: INDIA
Distribution: All Linux & Unix
Posts: 86

Rep: Reputation: 19
touch XXX.sh
chmod +x XXX.sh
vi XXX.sh
#!/bin/sh
xxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
:wq
 
0 members found this post helpful.
Old 07-01-2010, 06:38 AM   #3
izghitu
Member
 
Registered: Oct 2005
Location: localhost.localdomain
Distribution: CentOS
Posts: 108

Original Poster
Rep: Reputation: 16
this is supposed to be funny?
 
Old 07-01-2010, 07:02 AM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,490

Rep: Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956
Since this thread has been forced out of the zero reply list... I'll start to tell something (hopefully) useful.

@izghitu: if you need to improve or refresh your general knowledge about bash scripting, better to start from the official documentation, for example:

Bash Reference Manual
Bash Guide for Beginners
Advanced Bash Scripting Guide

just to mention some of them. Command lines arguments are often referred as positional parameters. Inside a bash script you can retrieve their value using $1, $2, $3 and so on. Or you can parse them one at a time using the shift built-in in a loop. However, what you really need is a way to manage command line's options. In this case the getopts built-in or the getopt external command are your friends. You might start to look for all these terms in the cited documentation. Hope this helps.

Last edited by colucix; 07-01-2010 at 07:03 AM.
 
Old 07-01-2010, 09:23 AM   #5
izghitu
Member
 
Registered: Oct 2005
Location: localhost.localdomain
Distribution: CentOS
Posts: 108

Original Poster
Rep: Reputation: 16
That's exactly what I was looking for

Thanks!
 
  


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
getting command line arguments in bash DEF. Programming 4 05-06-2009 11:50 AM
Bash command line arguments msreddy999 Programming 1 03-20-2009 02:56 PM
need some help regarding command line arguments kristam269 Linux - General 1 01-23-2007 09:40 AM
command line arguments nickraj Programming 6 09-11-2006 01:01 PM
Command line arguments?? almagerenia Linux - Newbie 1 09-08-2006 04:05 AM


All times are GMT -5. The time now is 09:19 AM.

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