The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Pass Kill with arguments aksmuralee UNIX for Advanced & Expert Users 4 04-25-2008 05:07 AM
Is there a limit to the no. of arguments to a shell script ? hidnana Shell Programming and Scripting 4 03-17-2008 12:19 PM
pass arguments to called program ShellUser Shell Programming and Scripting 2 01-22-2008 09:34 AM
To Write a Shell script that takes two arguments. bobby36 Shell Programming and Scripting 3 04-05-2007 08:44 PM
Shell script with arguments sankar6254 Shell Programming and Scripting 3 12-22-2003 09:21 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-10-2004
preetikate preetikate is offline
Registered User
  
 

Join Date: Feb 2004
Posts: 13
How to pass arguments to a function in a shell script?

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!
  #2 (permalink)  
Old 02-10-2004
druuna
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
.....

Last edited by druuna; 05-21-2009 at 09:16 AM..
  #3 (permalink)  
Old 02-10-2004
norsk hedensk norsk hedensk is offline Forum Advisor  
Registered User
  
 

Join Date: Jul 2002
Location: new york
Posts: 1,025
in bash the variables are global, so a variable established somewhere else can be used an a separate function. i am not sure about variables assigned in another function however. check out tldp.org and search for the "advanced bash shell scripting guide", if youre using bash.
  #4 (permalink)  
Old 03-01-2004
karthi_tvr karthi_tvr is offline
Registered User
  
 

Join Date: Mar 2004
Location: Singapore
Posts: 5
Smile

Hi Preeti

You can pass variables to functions and use them within for modification. Once you exit the function, the variables still continue to hold the same values. So you need not worry abt the changes as long as your vaiable names within the function and outside the function are same.

Else you can do as follows :-

example_func()
{
echo "Var1 is $1"
echo "Var2 is $2"
Var1=`echo $Var1 + 10`
Var2=`echo $Var2 + 15`
echo "Var1 is $Var1"
echo "Var2 is $Var2"
}

-
-
example_func $Var1 $Var2
-
-
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:47 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0