LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices

Reply
 
Search this Thread
Old 05-21-2007, 07:07 AM   #1
indikabandara19
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)

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

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
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.
 
Old 05-21-2007, 08:43 AM   #3
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,393
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.
Code:
grep $*
 
Old 05-21-2007, 09:26 AM   #4
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

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

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

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


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
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


All times are GMT -5. The time now is 07:25 PM.

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