The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
global variable not being set robotball Shell Programming and Scripting 5 06-10-2008 06:20 AM
global variable in awk anhtt Shell Programming and Scripting 1 03-16-2008 03:55 PM
Problem with global and local variables qzv2jm Shell Programming and Scripting 2 03-04-2008 01:18 PM
Global Variable in awk... ZINGARO Shell Programming and Scripting 1 07-04-2007 01:07 PM
Reg. Local vs Global declarations kms High Level Programming 2 05-02-2005 09:30 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-29-2004
odashe318 odashe318 is offline
Registered User
  
 

Join Date: Oct 2004
Posts: 8
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 variable as global.
Can anybody explain this?


#!/usr/bin/ksh

typeset var

function f2
{
var=1111
}

function f1
{
typeset lpt=tmp
var=alpha
f2 | wc $lpt
print "after f2 call, \$var is $var"
}

f1

  #2 (permalink)  
Old 10-29-2004
bhargav's Avatar
bhargav bhargav is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2004
Location: USA
Posts: 511
some thing wrong with the line

f2 | wc $lpt in tr script
  #3 (permalink)  
Old 10-29-2004
odashe318 odashe318 is offline
Registered User
  
 

Join Date: Oct 2004
Posts: 8
Lightbulb

Sorry, should be
f2| wc >$lpt

or just

f2 | wc

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:53 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0