LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 07-08-2013, 12:21 PM   #1
jscottcc
LQ Newbie
 
Registered: Aug 2012
Posts: 11

Rep: Reputation: 0
Reading files in a directory into a Kornshell array.


So I'm trying to get the filenames in a directory read into an array over ssh. The way I'm currently doing it is as follows:
Code:
set -A file_array $(ssh example@42.42.42.42 ls /home/example/directory)
typeset -L14 filename
typeset -i idx=0
typeset -i total=0

total=$(ssh example@42.42.42.42 ls /home/example/directory | wc -l)-1

while [[ $idx -le $total ]]
do
     filename=${file_array[$idx]}
done
So the question isn't why this doesn't work, but why it does. Everything makes relative sense to me, other than the -L14 flag in line two. I did some googling (though admittedly it wasn't extensive) and wasn't able to dig anything up on it. Can anyone help me out?

Also if there are ways I can make this more efficient or more reusable, I'd love to hear it.

Thanks.
 
Old 07-08-2013, 01:07 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Well first search got me: http://docstore.mik.ua/orelly/unix3/korn/ch06_05.htm, for the -Ln option

As for the array assignment, $() returns the output of a command and 'set -A' creates the array to store the information in.
 
  


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
store files in a directory in an array meet10may Linux - Newbie 6 06-04-2012 11:48 AM
[SOLVED] reading files in a directory using bash vjramana Programming 5 11-07-2010 11:16 PM
Reading all files in a directory in an alphabetical order weeshalll Programming 7 11-25-2009 10:28 PM
How to copy files after search in array from this directory to another directory! phanvinhgiap Programming 4 01-04-2009 06:48 PM
Deleting unwanted files from any directory without reading each Karthikeyan Gurusamy Linux - Newbie 3 12-24-2005 01:48 AM

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

All times are GMT -5. The time now is 05:51 AM.

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