j***n 发帖数: 9 | 1 I have multiple *.out files in the current directory.
>ls *.out
a.out b.out c.out
I can use the following command to get the file counts:
>ls -l *.out | wc -l
3
And then I want to allocate the file name to an array as the
following;
file[1]=a.out
file[2]=b.out
file[3]=c.out
Does ls has the function to list first, second, third,
...etc file and then I can use a loop to accomplish this?
Like
while [[ file_count -le file_number ]] #in this case, file
number is 3
do
file[file_count]=`ls *.out ?? | a***n 发帖数: 262 | 2 #!/bin/sh -xv
for name in `ls -*.out`
do
do whatever you want
done
【在 j***n 的大作中提到】 : I have multiple *.out files in the current directory. : >ls *.out : a.out b.out c.out : I can use the following command to get the file counts: : >ls -l *.out | wc -l : 3 : And then I want to allocate the file name to an array as the : following; : file[1]=a.out : file[2]=b.out
| c*****t 发帖数: 1879 | 3
^^^^^^^^^^^
just
for name in *.out
is enough
【在 a***n 的大作中提到】 : #!/bin/sh -xv : for name in `ls -*.out` : do : do whatever you want : done
|
|