Sponsored Content
Top Forums UNIX for Advanced & Expert Users Setting global variables with BASH/Linux Post 302260403 by stanleypane on Thursday 20th of November 2008 12:00:55 PM
Old 11-20-2008
You shouldn't have to use export to make variables within a function become global. Once a function is run, it's variables should be available throughout the rest of your script.

If you are invoking a subshell (while statement?) in one of your functions, that's another story. It would help to see the other functions to debug this problem.

Are you certain that the values from Function 1 are being passed to Function 2 when using the pipe? If you want to pass a variable to your second function, I'd do it like this:

Code:
func1 () {
var1=1
}

func2 () {
var2=$1
}

func1
func2 $var1

echo $var2

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Global PATH setting

I am using Solaris 8 and I want to change the PATH setting for all users. I have edited /etc/profile, but when I log in and check the PATH variable, it hasn't changed. Am I missing something? (5 Replies)
Discussion started by: jxh
5 Replies

2. UNIX for Dummies Questions & Answers

setting global variable for all users

hi, i am a newbie unix administrator. i want to set a variable, let's say : alias cls 'clear' But i am not going to add this line in the .login file for every home directory of my 500+ users. pls tell me where should i put this line in, so that all users can use this variable after... (4 Replies)
Discussion started by: champion
4 Replies

3. Shell Programming and Scripting

perl global variables

Can someone give me "the lecture" on why you shouldn't make all your varables global when programming in perl. I have been doing this but I have heard that it is not a good practice. (3 Replies)
Discussion started by: reggiej
3 Replies

4. UNIX for Dummies Questions & Answers

setting a global variable in script

Hi All, I know to set global variable i can use export .. But take the situation like below .. I want to set a variable in one script and access that in second script i have done like this .. It is not working one.sh #!/usr/bin/ksh echo $RISSHI export RISSHI=1 two.sh... (3 Replies)
Discussion started by: arunkumar_mca
3 Replies

5. UNIX for Dummies Questions & Answers

global variables

Hi, I hav created a script that calls a sub-script. In both the scripts i called the configuration file. Now i wanted to use a variable that should be used in both script and sub-script files. Actually, i wanted to return a file name and the return status to the script file from the sub-script.... (6 Replies)
Discussion started by: Swapna173
6 Replies

6. Solaris

How to access ENV variables of non global zones in global zone???

Hi Guys, My requirement is I have file called /opt/orahome/.profile in non global zone. PATH=/usr/bin:/usr/ucb:/etc:/usr/sbin:/usr/local/bin:/usr/openwin/bin:. export PATH PS1="\${ORACLE_SID}:`hostname`:\$PWD$ " export PS1 EDITOR=vi export EDITOR ENV=/opt/orahome/.kshrc export ENV... (1 Reply)
Discussion started by: vijaysachin
1 Replies

7. UNIX for Advanced & Expert Users

Setting a permanent global variable in unix accessible from any script

Is there anyway in which i can set a permanent global variable in unix, which when initialised with a value and modified during any shell script, would retain its value even if i logout and login I dont know whether i am being able to express my need clearly but basically what i want is a... (3 Replies)
Discussion started by: arindamlive
3 Replies

8. UNIX for Dummies Questions & Answers

Global variables in perl

hi all, i need a help for the following query. Thanks in advance for your valuable time. i have a main.pl file which has a global variable declared as below. our myVar=0; call first.pl script from the main.pl script. print the value of myVar (the value is still 0 and not 10.) i have a... (1 Reply)
Discussion started by: hemalathak10
1 Replies

9. Shell Programming and Scripting

'Dynamic' setting of variables in bash script

Hi all, I want to dynamically set variables in a bash script. I made a naive attempt in a while loop that hopefully can clarify the idea. n=0; echo "$lst" | while read p; do n=$(($n+1)); p"$n"="$p"; done The error message is: bash: p1=line1: command not found bash: p2=line2: command... (8 Replies)
Discussion started by: jeppe83
8 Replies

10. Shell Programming and Scripting

Bash: Setting default values for variables

I have a variable I want to use in bash script. The user will pass an argument to the script and I will store it in `arg_fql`. If the user does not pass the variable, I still never set arg_fql, but I set another variable to a default. However, if the user passes a value, `arg_fql` will be set to... (2 Replies)
Discussion started by: kristinu
2 Replies
ExtUtils::Mksymlists(3pm)				 Perl Programmers Reference Guide				 ExtUtils::Mksymlists(3pm)

NAME
ExtUtils::Mksymlists - write linker options files for dynamic extension SYNOPSIS
use ExtUtils::Mksymlists; Mksymlists( NAME => $name , DL_VARS => [ $var1, $var2, $var3 ], DL_FUNCS => { $pkg1 => [ $func1, $func2 ], $pkg2 => [ $func3 ] ); DESCRIPTION
"ExtUtils::Mksymlists" produces files used by the linker under some OSs during the creation of shared libraries for dynamic extensions. It is normally called from a MakeMaker-generated Makefile when the extension is built. The linker option file is generated by calling the function "Mksymlists", which is exported by default from "ExtUtils::Mksymlists". It takes one argument, a list of key-value pairs, in which the following keys are recognized: DLBASE This item specifies the name by which the linker knows the extension, which may be different from the name of the extension itself (for instance, some linkers add an '_' to the name of the extension). If it is not specified, it is derived from the NAME attribute. It is presently used only by OS2 and Win32. DL_FUNCS This is identical to the DL_FUNCS attribute available via MakeMaker, from which it is usually taken. Its value is a reference to an associative array, in which each key is the name of a package, and each value is an a reference to an array of function names which should be exported by the extension. For instance, one might say "DL_FUNCS => { Homer::Iliad => [ qw(trojans greeks) ], Homer::Odyssey => [ qw(travellers family suitors) ] }". The function names should be identical to those in the XSUB code; "Mksymlists" will alter the names written to the linker option file to match the changes made by xsubpp. In addition, if none of the functions in a list begin with the string boot_, "Mksymlists" will add a bootstrap function for that package, just as xsubpp does. (If a boot_<pkg> function is present in the list, it is passed through unchanged.) If DL_FUNCS is not specified, it defaults to the bootstrap function for the extension specified in NAME. DL_VARS This is identical to the DL_VARS attribute available via MakeMaker, and, like DL_FUNCS, it is usually specified via MakeMaker. Its value is a reference to an array of variable names which should be exported by the extension. FILE This key can be used to specify the name of the linker option file (minus the OS-specific extension), if for some reason you do not want to use the default value, which is the last word of the NAME attribute (e.g. for "Tk::Canvas", FILE defaults to "Canvas"). FUNCLIST This provides an alternate means to specify function names to be exported from the extension. Its value is a reference to an array of function names to be exported by the extension. These names are passed through unaltered to the linker options file. Specifying a value for the FUNCLIST attribute suppresses automatic generation of the bootstrap function for the package. To still create the bootstrap name you have to specify the package name in the DL_FUNCS hash: Mksymlists( NAME => $name , FUNCLIST => [ $func1, $func2 ], DL_FUNCS => { $pkg => [] } ); IMPORTS This attribute is used to specify names to be imported into the extension. It is currently only used by OS/2 and Win32. NAME This gives the name of the extension (e.g. "Tk::Canvas") for which the linker option file will be produced. When calling "Mksymlists", one should always specify the NAME attribute. In most cases, this is all that's necessary. In the case of unusual extensions, however, the other attributes can be used to provide additional information to the linker. AUTHOR
Charles Bailey <bailey@newman.upenn.edu> REVISION
Last revised 14-Feb-1996, for Perl 5.002. perl v5.18.2 2014-01-06 ExtUtils::Mksymlists(3pm)
All times are GMT -4. The time now is 07:36 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy