![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
| Global Variable in a script? | skyineyes | Shell Programming and Scripting | 2 | 07-12-2007 06:55 AM |
| Global Variable in awk... | ZINGARO | Shell Programming and Scripting | 1 | 07-04-2007 01:07 PM |
| Global variable becomes local | odashe318 | Shell Programming and Scripting | 2 | 10-29-2004 09:18 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Global variable
I have written a shell scritp in which i am using a variable which is declared before a while loop and i am updaitng the variable in while loop and want to use its updated value outside the loop. I am not able to do so, b'coz the scope of the variable is limited to the while loop only and when i am using the variable outside the loop its using the value which i initialized to the variable before the loop.
I think i have to use global variable, but i dont know how to make & use global variable. Plz respond asap |
|
||||
|
Quote:
i think this should work. give a try. Also tell which shell you are using. Thanks namish Last edited by namishtiwari; 06-12-2008 at 06:23 AM.. |
|
||||
|
i m using bash
and my code is like this /* Code starts here */ counter=1 file="" ls -1tr abc* | while read record do if [ counter -ne 0 ] file=${record} counter=0 fi done rfile=${file} /* EOF */ now my rfile is empty it has no value, but if i echo file variable in while it is having some value, i want to use that value outside. Please suggest me a solution asap |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|