The UNIX and Linux Forums  

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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Declaring Global Variables in KLD int80h BSD 1 01-21-2008 05:11 AM
global variables in KLD (FreeBSD) int80h High Level Programming 0 01-17-2008 04:14 PM
perl global variables reggiej Shell Programming and Scripting 3 08-29-2005 05:18 AM
Reg. Local vs Global declarations kms High Level Programming 2 05-02-2005 06:30 AM
Global variable becomes local odashe318 Shell Programming and Scripting 2 10-29-2004 06:18 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-03-2008
Registered User
 

Join Date: Feb 2008
Posts: 6
Red face 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.......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 12:10 AM.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-04-2008
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,854
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.
Reply With Quote
  #3 (permalink)  
Old 03-04-2008
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,002
or better yet - to get the 'active' shell interpreter:
Code:
echo $0
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:16 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0