Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 05-21-2007, 07:07 AM   #1
LQ Newbie
Registered: May 2007
Posts: 18

Rep: Reputation: 0
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?
Old 05-21-2007, 07:45 AM   #2
LQ Veteran
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389

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.
Old 05-21-2007, 08:43 AM   #3
Senior Member
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,402
Blog Entries: 1

Rep: Reputation: 64
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 $*
Old 05-21-2007, 09:26 AM   #4
Senior Member
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

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

Old 05-21-2007, 10:40 PM   #5
LQ Newbie
Registered: May 2007
Posts: 18

Original Poster
Rep: Reputation: 0
thanks.. u've pointed me in correct direction


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
passing variable from bash to perl in a bash script quadmore Programming 6 02-21-2011 04:11 AM
Bash Script Variable Problem jimmy512 Programming 5 05-11-2007 07:38 AM
can awk see bash script arguments ? sharapchi Programming 7 12-14-2006 08:03 PM
BASH Script: variable values referencing for console arguments sadarax Programming 1 11-14-2005 05:23 PM
bash script $n variable expansion cortez Programming 6 12-08-2003 04:03 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:00 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration