本文介绍了Linux的迭代在目录中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想遍历目录中的每个文件。这里是我的code为止。

 同时读取inputline

  输入=$ inputline
  回声您输入$输入;如果[-d$ {}输入]
  然后
    回声好工作,这是一个目录!    在$输入端D
      做
        回声这是在目录$ d个。
      DONE
   出口

我的输出总是只有一行

 这是$输入目录。

为什么没有这个code的工作?我究竟做错了什么?

酷。当我赞同它打印出

  $输入/文件

为什么会这样?难道不应该只是打印出来的文件,而不目录preFIX?


解决方案

 在$输入D / *

I'm trying to iterate over each file in a directory. Here's my code so far.

while read inputline
do
  input="$inputline"
  echo "you entered $input";

if [ -d "${input}" ]
  then
    echo "Good Job, it's a directory!"

    for d in $input
      do
        echo "This is $d in directory."
      done
   exit

my output is always just one line

this is $input directory.

why isn't this code working? what am I doing wrong?

Cool. When I echo it prints out

$input/file

Why does it do that? Shouldn't it just print out the file without the directory prefix?

解决方案
for d in "$input"/*

这篇关于Linux的迭代在目录中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 22:37