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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Array in loop is acting up RisingSun Shell Programming and Scripting 5 08-07-2008 02:21 PM
reading from within the loop --std i/p problem mobydick Shell Programming and Scripting 2 07-11-2008 08:42 PM
How to use array values after the loop. Devesh5683 Shell Programming and Scripting 1 05-13-2008 07:38 PM
Array Declaration and For Loop 33junaid Shell Programming and Scripting 4 09-15-2007 04:16 PM
Reading data into muti-dimentional array - in perl zap Shell Programming and Scripting 5 05-04-2004 10:15 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-12-2008
ssuresh1999 ssuresh1999 is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 51
Reading from while loop into an array

Hi
I have something like
cat $HOME/all_dirs | while read ln_old_dirs
do
if [ "$ln_all_old_dirs" != "" ]
then
echo "$ln_all_old_dirs"
fi
done

As you know that the variable ln_all_old_dirs is not accessable from outside the while loop
How to assign it in an array so that i can use it outside
It would be of great help
Thanks in advance
Suresh
  #2 (permalink)  
Old 08-12-2008
ynilesh's Avatar
ynilesh ynilesh is offline
Registered User
  
 

Join Date: Oct 2007
Location: Bangalore, India.
Posts: 222
Code:
#!/bin/bash
array=(red green blue yellow magenta)
len=${#array[*]}
echo "The array has $len members. They are:"
i=0
while [ $i -lt $len ]; do
	echo "$i: ${array[$i]}"
	let i++
done
Take a reference from this script.

- nilesh
  #3 (permalink)  
Old 08-12-2008
ssuresh1999 ssuresh1999 is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 51
Hi nilesh
Thanks for your reply but mine is not fixed array it can have any number of entries greater than zero
array=($ln_all_old_dirs)
len=${#array[*]}
echo "The array has $len members. They are:"
i=0
while [ $i -lt $len ]; do
echo "$i: ${array[$i]}"
let i++
done
This is not working for me
moreover my main question is how to access set of values that is array outsid the loop
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 08:35 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