LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-01-2012, 06:56 AM   #16
diamond_D
Member
 
Registered: Jul 2005
Posts: 51

Original Poster
Rep: Reputation: 0

How can I capture the results of 'ls -l' to store in an array. This way I can create a seperate function to manipulate the array elements as needed.
 
Old 08-01-2012, 08:37 AM   #17
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by diamond_D View Post
How can I capture the results of 'ls -l' to store in an array. This way I can create a seperate function to manipulate the array elements as needed.
I think you're on the wrong track, this sounds too complicated. Also, don't parse ls.

Code:
    for file in "${item}"/* ; do
        if [ -f "${file}" ] ; then
            echo "Here is output from ${file}" >> content.txt
            cat "${file}" >> content.txt
        fi
    done
 
Old 08-01-2012, 02:44 PM   #18
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,979
Blog Entries: 1

Rep: Reputation: 209Reputation: 209Reputation: 209
Quote:
Originally Posted by diamond_D View Post
How can I capture the results of 'ls -l' to store in an array. This way I can create a seperate function to manipulate the array elements as needed.
To answer your question...
Code:
#!/bin/bash
items=( $(ls -1 /etc ) )
for item in ${items[@]}
do
  file /etc/${item}
done
-C
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
check file existence in your directory ust Linux - Newbie 6 07-27-2011 05:12 AM
[SOLVED] Need bash script to check existence of images within an HTML document thunor Programming 7 10-26-2010 10:20 AM
[bash] Remote file existence check danket Linux - Newbie 5 01-14-2008 04:39 PM
[Question] Check File existence hbinded Programming 3 12-19-2006 05:15 PM
check for existence of file j-me Linux - Newbie 5 07-29-2003 07:58 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:43 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration