If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > How to pass arguments to a function?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-10-04, 02:33
preetikate preetikate is offline
Registered User
 
Join Date: Jan 2004
Posts: 84
How to pass arguments to a function?

Hi,
I have two shell variables $t1 and $t2 which I need to pass to a function in a shell script. The function will do some computation with those two variables and echo the resultant. But I do not know how to pass teh arguments.
The function written is
f1()
{......
........
}

What should be the syntax to pass arguments $t1 and $t2 to this function.
Help would be appreciated!
Reply With Quote
  #2 (permalink)  
Old 02-10-04, 03:13
reneeb reneeb is offline
Registered User
 
Join Date: Jan 2004
Location: Germany
Posts: 167
may be this example will help you:
Code:
#!/bin/bash

function count_from_to()
{
  i=$1			# i gets value of param1
  while [ $i -le $2 ]	# while param2 greater than i
  do
    echo $i		# print i
    let i=$i+1		# increment i
  done
}

# main program

read -p "from: " number1	# reading starting number
read -p "to: " number2		# reading final number
count_from_to $number1 $number2	# call function passing the two values
__________________
board.perl-community.de - The German Perl-Community
Reply With Quote
  #3 (permalink)  
Old 02-10-04, 03:30
preetikate preetikate is offline
Registered User
 
Join Date: Jan 2004
Posts: 84
Thanks a lot!
Its done now!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On