遞歸查找具有特定擴展名的文件 - Recursively look for files with a specific extension

問題:

I'm trying to find all files with a specific extension in a directory and its subdirectories with my bash (Latest Ubuntu LTS Release).我正在嘗試使用我的 bash(最新的 Ubuntu LTS 版本)在目錄及其子目錄中查找具有特定擴展名的所有文件。

This is what's written in a script file:這是寫在腳本文件中的內容:

#!/bin/bash

directory="/home/flip/Desktop"
suffix="in"

browsefolders ()
  for i in "$1"/*; 
  do
    echo "dir :$directory"
    echo "filename: $i"
    #   echo ${i#*.}
    extension=`echo "$i" | cut -d'.' -f2`
    echo "Erweiterung $extension"
    if     [ -f "$i" ]; then        

        if [ $extension == $suffix ]; then
            echo "$i ends with $in"

        else
            echo "$i does NOT end with $in"
        fi
    elif [ -d "$i" ]; then  
    browsefolders "$i"
    fi
  done
}
browsefolders  "$directory"

Unfortunately, when I start this script in terminal, it says:不幸的是,當我在終端中啓動這個腳本時,它說:

[: 29: in: unexpected operator

(with $extension instead of 'in' ) (用$extension而不是'in'

What's going on here, where's the error?這是怎麼回事,錯誤在哪裏? But this curly brace但是這個花括號


解決方案:

參考一: https://en.stackoom.com/question/Oryj
參考二: https://stackoom.com/question/Oryj
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章