-   Linux - Newbie (
-   -   bash script - variable arguments (

indikabandara19 05-21-2007 08: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)

[you fill this]
grep [you fill this]

here is how i want to use it
./ -Rn pattern file is expected to pass all arguments to grep
how can u do it?

druuna 05-21-2007 08:45 AM


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 09: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.

grep $*

theYinYeti 05-21-2007 10:26 AM

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


indikabandara19 05-21-2007 11:40 PM

thanks.. u've pointed me in correct direction

All times are GMT -5. The time now is 08:30 PM.