Problem with global and local variables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with global and local variables
# 1  
Old 03-04-2008
Power Problem with global and local variables

Guys, how can I define global variables in sorlaris...cause I lose the values outside the scope.

Rite now wat I do is,I redirect variable value to a file n then get it back outside the function...Smilie....theres obviously a better way of doing this...I now this is a basic question....but please help.....

Last edited by qzv2jm; 03-04-2008 at 04:10 AM..
# 2  
Old 03-04-2008
Are you talking about C?
Code:
int this_is_global=0;

void foo(void)
{
    this_is_global=7;
}

int main()
{
      printf("before: %d ", this_is_global);
      foo();
      printf(" after: %d\n", this_is_global);
}

Is it shell script? - the syntax depends on what shell you are using
Code:
echo $SHELL

will show you your shell. We need to know which shell you are using.
# 3  
Old 03-04-2008
or better yet - to get the 'active' shell interpreter:
Code:
echo $0

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Problem in Global variables in shell script

hi, i have a shell script which calls another shell which in turn calls another shell script. Main_shell_script.sh echo "In Main_shell_script.sh" FILENAME="original.txt" # LINE 1 DST_FILENAME=$FILENAME # LINE 2 echo "FILENAME = {$FILENAME}" echo "DST_FILENAME =... (3 Replies)
Discussion started by: Little
3 Replies

3. UNIX for Dummies Questions & Answers

Global - Local script??

Hi, I have a script which can be called from any path on the machine. It kind of acts like a global script. How do I achive this? :confused: The path from which I call it is different from the path where it exists. (where <script name> ) Thanks and Regards, Preetham R. (1 Reply)
Discussion started by: preethgideon
1 Replies

4. HP-UX

Seeing different output from who -u in global INIT and local SRP

I am seeing different output from "who -u" when we execute "who -u" in global INIT and local SRP after calling telnet, rlogin and remsh. We are not seeing correct output when we login to local SRP using telnet, rlogin and remsh. srp_init just creates an UTMP entry in the UTMP database. Based my... (1 Reply)
Discussion started by: madhur.tripathi
1 Replies

5. 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

6. Solaris

sharing a directory between local and global zone

is this the step? add fs set dir=/export set special=/export set type=lofs add options rw end i notice i can't post immediately, moderator needs to moderate. i have 1 more post still haven't appear in the forum..hmm.... (1 Reply)
Discussion started by: binary0011
1 Replies

7. 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

8. 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

9. Programming

Reg. Local vs Global declarations

Please go through the following two versions of code :- Version 1 --- string1 and string2 declared as Global variables The output is :-- (as expected sprintf is overwriting the first byte of string2 with NULL) string1=send string2= #include <stdio.h> char string1; char string2; main()... (2 Replies)
Discussion started by: kms
2 Replies

10. Shell Programming and Scripting

Global variable becomes local

I have encountered a very weird behavior of a global variable in Korn Shell in AIX: A function f1 in my script pipes the output of the function f2 to a program. A variable defined as global using typeset gets its value in f2. That value is not seen in f1. If I remove the pipe ksh recognizes the... (2 Replies)
Discussion started by: odashe318
2 Replies
Login or Register to Ask a Question