LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   bash script - variable arguments (http://www.linuxquestions.org/questions/linux-newbie-8/bash-script-variable-arguments-555526/)

indikabandara19 05-21-2007 07:07 AM

bash script - variable arguments
 
hope this is the correct place to post...otherwise please redirect me

how can i pass all the arguments of a shell script inside? i.e instead of using $1,$2 etc


eg. say i want to wrap grep(as i have nothing better to do)

----a.sh---------
#!/bin/bash

[you fill this]
grep [you fill this]

----a.sh---------

here is how i want to use it
./a.sh -Rn pattern file

a.sh is expected to pass all arguments to grep
how can u do it?

druuna 05-21-2007 07:45 AM

Hi,

Take a look at bash' getopt.

Here are 2 sites dealing with just that:

More Power with Bash Getopts
Getopt and getopts

Also take a look at Advanced Bash Scripting

Hope this helps.

marozsas 05-21-2007 08:43 AM

druuna give you the right directions to learn more about how to handle arguments in shell.

However, a short answer is to use "$*" which expand for all arguments in cmd line.
Code:

grep $*

theYinYeti 05-21-2007 09:26 AM

Not quite. You'll use "$@" (WITH the quotes). See bash man page for details.

Yves.

indikabandara19 05-21-2007 10:40 PM

thanks.. u've pointed me in correct direction


All times are GMT -5. The time now is 03:02 AM.