由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Unix版 - Shell Script Question
相关主题
Help! shell programmingwhere can I find some good website for C Shell ?
新手求助shell scriptShell Script
segmentation fault when using "script"为什么我就是不会写Shell script?
"#! /bin/csh" != "#!/bin/csh" ??????How to set environment variables for CGI scripts?
如何在perl中运行c-shell file?how to convert csh shell script to dos batch file
菜鸟2问题-about shell programminga question in shell script
which shell is best?[转载] a question about shell script
shell programmingShell Script Question about Hostname
相关话题的讨论汇总
话题: file话题: ls话题: out话题: script话题: question
进入Unix版参与讨论
1 (共1页)
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

1 (共1页)
进入Unix版参与讨论
相关主题
Shell Script Question about Hostname如何在perl中运行c-shell file?
Help on shell script菜鸟2问题-about shell programming
[转载] Re: shell script questionwhich shell is best?
Korn shell scriptshell programming
Help! shell programmingwhere can I find some good website for C Shell ?
新手求助shell scriptShell Script
segmentation fault when using "script"为什么我就是不会写Shell script?
"#! /bin/csh" != "#!/bin/csh" ??????How to set environment variables for CGI scripts?
相关话题的讨论汇总
话题: file话题: ls话题: out话题: script话题: question