LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-01-2007, 02:03 AM   #1
kalyanofb
LQ Newbie
 
Registered: Feb 2007
Posts: 21

Rep: Reputation: 15
Shell: Getting Arguments


getDetails()
{
for i in $1; do

done
}

getDetails outfn arg1 arg2 arg3

The above is script model. I want to store some information to argument1 while processing for loop. How i will do this.

Help me plz.
 
Old 03-01-2007, 02:31 AM   #2
puffinman
Member
 
Registered: Jan 2005
Location: Atlanta, GA
Distribution: Gentoo, Slackware
Posts: 217

Rep: Reputation: 31
Not quite sure exactly what you mean, but is it something along these lines?

Code:
getDetails() {
  OUTFN=$1;
  shift;
for arg in $*;
  do
  #do whatever you want to do here...
  echo $arg >> $OUTFN
done
}
 
Old 03-01-2007, 02:36 AM   #3
kalyanofb
LQ Newbie
 
Registered: Feb 2007
Posts: 21

Original Poster
Rep: Reputation: 15
How i will skip the first argument inside the loop
 
Old 03-01-2007, 03:25 AM   #4
puffinman
Member
 
Registered: Jan 2005
Location: Atlanta, GA
Distribution: Gentoo, Slackware
Posts: 217

Rep: Reputation: 31
That's what the shift does...
 
Old 03-01-2007, 11:20 AM   #5
cfaj
Member
 
Registered: Dec 2003
Location: Toronto, Canada
Distribution: Mint, Mandriva
Posts: 221

Rep: Reputation: 31
Quote:
Originally Posted by puffinman
Not quite sure exactly what you mean, but is it something along these lines?

Code:
getDetails() {
  OUTFN=$1;
  shift;
for arg in $*;
  do
  #do whatever you want to do here...
  echo $arg >> $OUTFN
done
}
Use "$@" not $*, printf rather than echo, and quote your variables:

Code:
getDetails() {
  OUTFN=$1;
  shift;
  for arg in "$@"
  do
    #do whatever you want to do here...
    printf "%s\n" "$arg"
  done > $OUTFN
}
 
  


Reply



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
shell scripts wrappers and passing arguments nosbod Programming 2 09-21-2006 08:27 AM
Hiding arguments in shell scripts 3saul Linux - Software 2 01-09-2006 02:44 PM
Passing arguments to a shell script subu_s Programming 3 09-02-2005 05:13 AM
help changing case on arguments to bourne shell script Maldain Programming 2 05-03-2005 10:18 AM
number of command line arguments to shell u4u Linux - General 1 03-04-2005 06:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:20 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration