avatar
j*n
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 ??
avatar
a*n
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

avatar
c*t
3

^^^^^^^^^^^
just
for name in *.out
is enough

【在 a***n 的大作中提到】
: #!/bin/sh -xv
: for name in `ls -*.out`
: do
: do whatever you want
: done

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。