LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   bash command line arguments (http://www.linuxquestions.org/questions/linux-software-2/bash-command-line-arguments-817368/)

izghitu 07-01-2010 06:16 AM

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

subho.d 07-01-2010 06:35 AM

touch XXX.sh
chmod +x XXX.sh
vi XXX.sh
#!/bin/sh
xxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
:wq

izghitu 07-01-2010 06:38 AM

this is supposed to be funny?

colucix 07-01-2010 07:02 AM

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.

izghitu 07-01-2010 09:23 AM

That's exactly what I was looking for

Thanks!


All times are GMT -5. The time now is 05:31 PM.