Re: put find output in an array
- From: "First Lensman" <1st.lensman@xxxxxxxxx>
- Date: 26 Aug 2006 13:15:49 -0700
how do I get this into an array?
In the Korn Shell there is an ability to execute a command and put the
results into an array:
#!/bin/ksh
set -A myarray $(find ./ -name "*.pl")
let count=0
while (( $count < ${#myarray[*]} )); do
echo FILE: ${myarray[count]}
let count="count + 1"
done
Also, you could use perl:
#!/usr/bin/perl
open FINDEM,'find ./ -name "*.pl" |' or die "Cannot open pipe: $!\n";
@findarr = <FINDEM>;
for ($i = 0; $i <= $#findarr; $i++) {
print "FILE: $findarr[$i]";
}
You can also use this perl:
#!/usr/bin/perl
@findarr = `find ./ -name "*.pl"`;
for ($i = 0; $i <= $#findarr; $i++) {
print "FILE: $findarr[$i]";
}
But, I think the backtick ( ` ) operator has been deprecated and may
not be available in current or future versions of perl. I'm using
version 5.8.0 of perl -- not sure if this is current.
I didn't use your exact find command for my testing purposes. This will
at least give you a head start.
Hope this helps.
Art Ramos
.
- Follow-Ups:
- Re: put find output in an array
- From: John W. Krahn
- Re: put find output in an array
- From: Xicheng Jia
- Re: put find output in an array
- References:
- put find output in an array
- From: johnmmcparland
- put find output in an array
- Prev by Date: Re: newbie question: remove lines from text-file
- Next by Date: Re: Bourne Shell: scope of variables in while loop
- Previous by thread: Re: put find output in an array
- Next by thread: Re: put find output in an array
- Index(es):
Relevant Pages
|