How do I capture the output from the ls or find command to store all file names in an array?

前端 未结 4 2281
余生分开走
余生分开走 2020-12-30 20:12

Need to process files in current directory one at a time. I am looking for a way to take the output of ls or find and store the resulting value as

4条回答
  •  -上瘾入骨i
    2020-12-30 20:38

    for i in `ls`; do echo $i; done;
    

    can't get simpler than that!

    edit: hmm - as per Dennis Williamson's comment, it seems you can!

    edit 2: although the OP specifically asks how to parse the output of ls, I just wanted to point out that, as the commentators below have said, the correct answer is "you don't". Use for i in * or similar instead.

提交回复
热议问题