Sponsored Content
Top Forums UNIX for Beginners Questions & Answers How to call variable inside a function globally? Post 302989614 by jim mcnamara on Monday 16th of January 2017 08:02:44 AM
Old 01-16-2017
You need a variable with global scope:

Code:
#!/bin/bash
# this variable, foo, has global scope
# it has to be defined in the code before the function
foo=1

func()
{
   a=$(( foo +1 ))
   foo=$a
}

# main code block
echo "before function foo = $foo"
func
echo "after function foo = $foo"
exit

This User Gave Thanks to jim mcnamara For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

passing a variable inside a variable to a function

I would like to know how to pass a variable inside a variable to a function. sample code below -------------- for x in 1 9 do check_null $C$x ##call function to check if the value is null if then echo "line number:$var_cnt,... (2 Replies)
Discussion started by: KingVikram
2 Replies

2. Shell Programming and Scripting

Bash: how to call function having it's name in variable?

Hello. Looking for a method of modularizing my bash script, I am stuck with such a problem. For example, I have: MODULE_NAME="test" FUNCTION_NAME="run" How do I can a function with name test_run? (4 Replies)
Discussion started by: FractalizeR
4 Replies

3. Infrastructure Monitoring

diffrence between method call and function call in perl

Hello, I have a problem with package and name space. require "/Mehran/DSGateEngineLib/general.pl"; use strict; sub System_Status_Main_Service_Status_Intrusion_Prevention { my %idpstatus; my @result; &General_ReadHash("/var/dsg/idp/settings",\%idpstatus); #print... (4 Replies)
Discussion started by: Zaxon
4 Replies

4. Shell Programming and Scripting

variable inside variable inside loop headache

Hi Gurus I have a file called /tmp/CMDB which looks like this serial: 0623AN1208 hostname: server1 model: x4100 assetID: 1234 I am writing a for loop that will go through this file line by line creating a variable of itself. Using the first iteration of the loop (i.e. the first line) as... (6 Replies)
Discussion started by: hcclnoodles
6 Replies

5. Shell Programming and Scripting

How to declare a variable which can be accessed globally

Hi I've few shell scripts which are responsible for triggering the continuous builds for a specific module. Each shell script is for a Module. Shell script has some module specific settings in the beginning and then it triggers the builds (which are nothing but some combination of Java programs... (2 Replies)
Discussion started by: kgsrinivas
2 Replies

6. Shell Programming and Scripting

After exit from function it should not call other function

Below is my script that is function properly per my conditions but I am facing one problem here that is when one function fails then Iy should not check other functions but it calls the other function too So anyone can help me how could i achieve this? iNOUT i AM GIVING TO THE... (1 Reply)
Discussion started by: rohit22hamirpur
1 Replies

7. Shell Programming and Scripting

Error during Accessing Global variable inside function

emailid=myemail@xyz.com taskName="DB-Backup" starttime=`date` email() { subject="$taskName" ": " $* " at `date` " mutt -s "$subject" $emailid < /dev/null } email "Starting" #do my stuff email "Finished" The above code gives following error ./dbbackup.sh: line 6: :... (5 Replies)
Discussion started by: nitiraj.rathore
5 Replies

8. Shell Programming and Scripting

Call function inside CASE

i have a case statement which branches to different sections based on an input. Each branch needs to call a function. below is the code. FOr some reason, the code inside the function is not getting executed. the code is below for reference. in the below code echo "Function 1" which is there... (2 Replies)
Discussion started by: cvsanthosh
2 Replies

9. Shell Programming and Scripting

Dereferencing variable inside egrep call

Hi guys I am trying to dereference a variable inside 'egrep -v ' command and getting a 'egrep: syntax error' : $ echo $exclude_list ts584d hf584db for i in `echo $exclude_list`; do egrep -v ${i} my_file done egrep: syntax error egrep: syntax error The syntax of the loop is correct.... (1 Reply)
Discussion started by: aoussenko
1 Replies

10. Shell Programming and Scripting

Need help on awk for printing the function name inside each function

Hi, I am having script which contains many functions. Need to print each function name at the starting of the function. Like below, functionname() { echo "functionname" commands.... } I've tried like below, func=`grep "()" scriptname | cut -d "(" -f1` for i in $func do nawk -v... (4 Replies)
Discussion started by: Sumanthsv
4 Replies
RUNKIT_METHOD_REDEFINE(3)						 1						 RUNKIT_METHOD_REDEFINE(3)

runkit_method_redefine - Dynamically changes the code of the given method

SYNOPSIS
bool runkit_method_redefine (string $classname, string $methodname, string $args, string $code, [int $flags = RUNKIT_ACC_PUBLIC]) DESCRIPTION
Note This function cannot be used to manipulate the currently running (or chained) method. Warning This function is EXPERIMENTAL. The behaviour of this function, its name, and surrounding documentation may change without notice in a future release of PHP. This function should be used at your own risk. PARAMETERS
o $classname - The class in which to redefine the method o $methodname - The name of the method to redefine o $args - Comma-delimited list of arguments for the redefined method o $code - The new code to be evaluated when $methodname is called o $flags - The redefined method can be RUNKIT_ACC_PUBLIC, RUNKIT_ACC_PROTECTED or RUNKIT_ACC_PRIVATE Note This parameter is only used as of PHP 5, because, prior to this, all methods were public. RETURN VALUES
Returns TRUE on success or FALSE on failure. EXAMPLES
Example #1 runkit_method_redefine(3) example <?php class Example { function foo() { return "foo! "; } } // create an Example object $e = new Example(); // output Example::foo() (before redefine) echo "Before: " . $e->foo(); // Redefine the 'foo' method runkit_method_redefine( 'Example', 'foo', '', 'return "bar! ";', RUNKIT_ACC_PUBLIC ); // output Example::foo() (after redefine) echo "After: " . $e->foo(); ?> The above example will output: Before: foo! After: bar! SEE ALSO
runkit_method_add(3), runkit_method_copy(3), runkit_method_remove(3), runkit_method_rename(3), runkit_function_redefine(3). PHP Documentation Group RUNKIT_METHOD_REDEFINE(3)
All times are GMT -4. The time now is 08:16 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy