Unable to access variable outside loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unable to access variable outside loop
# 1  
Old 05-23-2009
Unable to access variable outside loop

I am unable to access the value set inside the loop from outside loop .
Thought of taking this to forum , I had seen other replies also , where a pipe takes the execution to another shell and mentioned thats the reason we do not get the variable outside loop . But I am getting an issue and I am not using pipe . A sample code below . I do not know where I am going wrong .Any help would be highly appreciated.
(note my tree1.txt contains only 1 line , just trying to test if I can access the value for a variable set inside a while loop)
*************
count=0
while read line
do
count=10
echo $count
done < tree1.lst
echo count:$count
************Result**********
10
count:0
# 2  
Old 05-23-2009

You are using an old Bourne shell (perhaps /bin/sh on Solaris?).

Switch to a standard UNIX shell (/usr/xpg4/bin/sh or ksh).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unable to compare to a previous value of a variable in a while loop for a file

Hello All, I'm working on a script that will actually read a file consisting of data like the below:(ReportID,Sub_reportID,Sub_reportName) 1,1,ABC 1,2,DEF 1,3,GHI 2,1,JKL 2,2,MNO 3,1,PQR I want to read the Sub Report details for a Report_ID using while loop and write these values into... (6 Replies)
Discussion started by: venkat_reddy
6 Replies

2. Shell Programming and Scripting

Unable to set Global variable outside while loop

Below is my code: count=0 if ... ... else ... find * -prune -type d | sort -r -n | while read d; do count=1 if ; then echo "Count1:$count" ... ... break 2; fi ... done ... fi echo "Count2:$count" (9 Replies)
Discussion started by: mohtashims
9 Replies

3. UNIX for Dummies Questions & Answers

Unable to access current user's mailbox.

In any non-root account, whenever I enter mail, it gives me: /var/spool/mail/root: Permission deniedI am not logged in as root, why is mail accessing root's mailbox ? I am unable to enter the currently logged in user's mailbox. Any help is appreciated :) (2 Replies)
Discussion started by: Hijanoqu
2 Replies

4. Shell Programming and Scripting

Unable To access array in awk

Hi, i have the following code in which i am passing array tldn in awk using -v option & despite of that condition is not getting matched,can somebody suggest how to handle shell arrays in awk tcount=(9875 9667) awk -F"\t" -v ltldn="${tldn}" 'NR==FNR {POSTPAIDMDNS=$2"|"$3;next} ... (6 Replies)
Discussion started by: siramitsharma
6 Replies

5. AIX

P550 Unable to access Console

I have recently aquired the following machine: IBM,9113-550 Up until yesterday we could connect a dumb terminal to serial port 1 and get console login. However the dumb terminal died. We are now using a laptop with a null modem cable attached to serial port 1. This works perfectly for all of... (1 Reply)
Discussion started by: rsw7724
1 Replies

6. HP-UX

Unable to access TAR file

hi friends, I am using hp unix HP-UX B.11.11 .. Generally i do the compression to maintain the space availability . To compress the files first i used the TAR to collect all the files. it has done fine. when i am using command ls in the folder which has TAR file , it shows the TAR... (2 Replies)
Discussion started by: rdhaprakasam
2 Replies

7. Solaris

unable to access infodoc!!

Hi, I am refered to see Infodoc 80854. but I am not able to access from sun.com. Is there any precedure to view these?. Please guide me. Thanks in advance. (1 Reply)
Discussion started by: bpsunadm
1 Replies

8. Shell Programming and Scripting

Not access variable outside loop when a reading a file

I am writing a shell script using the korn shell. It seems that I am only able to use local variables within a while loop that is reading a file. (I can't access a variable outside a previously used while loop.) It's been a while since I wrote shell scripts. Here is a sample cat file.txt... (4 Replies)
Discussion started by: ricardo.ludwig
4 Replies

9. Shell Programming and Scripting

unable to access a variable not local to a while loop

I have a while loop like this cat ${filename} | while read fileline do ... done I need to access a variable value $newfile inside this while loop How will i do that?? (6 Replies)
Discussion started by: codeman007
6 Replies

10. Solaris

Unable to access home area

Good morning, I have a solaris 8 machine (Sunblade 1000) that is configured with NIS, I have checked everything I can think of to make sure everything is correctly configured which it appears it is but when I try to log into CDE it says it is unable to access my home area and it also does the... (1 Reply)
Discussion started by: Mr Pink
1 Replies
Login or Register to Ask a Question