![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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! |
|
||||
|
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.
|
|
||||
|
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 - - |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|