LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 06-15-2012, 02:27 AM   #1
dth4h
Member
 
Registered: Mar 2009
Posts: 51

Rep: Reputation: 10
Capturing info in an array is not working


I found this code
Code:
#! /bin/bash

i=1
ls | while read line
do
    array[ $i ]="$line"
    (( i++ ))
done
from this post


However the code is not working for me. Anytime I try to echo one of the array entries it doesn't display anything.
Is this code to old to work? It doesn't seem that old.

I run the code in the terminal like this:
Code:
i=1; ls | while read line;do array[$i]="$line"; (( i++ )); done
And it doesn't work.

This line works:
Code:
ls | while read line;do echo "$line"; done
It lists all the stuff in the current directory I am in on separate lines.

I am thinking maybe just the array part of the code is wrong.
 
Old 06-15-2012, 04:15 AM   #2
dth4h
Member
 
Registered: Mar 2009
Posts: 51

Original Poster
Rep: Reputation: 10
Nevermind. I found the answer.

Code:
i=1
while read line
do
    array[$i]="$line"
    (( i++ ))
done < <(ls)
 
  


Reply

Tags
array, bash, code, syntax


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
raid array metadata info (mdadm) suhas! Linux - Server 2 02-18-2011 04:26 AM
"cheese" capturing working a lot better under Ubuntu than Fedora ed_homeLinux Linux - Software 2 10-14-2008 07:32 PM
Working Grip 3.3.1 settings in Ubuntu 7.10 for FLAC with working meta info robocoop Linux - Software 0 04-06-2008 03:28 PM
mdadm (get my array working again) dadriver Linux - Software 1 01-20-2006 06:56 PM
Capturing video with Cinelerra works, capturing video with Xawtv doesn't! seaelf Slackware 0 06-27-2004 05:18 PM


All times are GMT -5. The time now is 06:11 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration