2
#!/bin/bash
#script to loop through directories to merge files

mydir=/data/
files="/data/*"

for f in $files
do
    if[ -d "$f" ]
    then
            for ff in $f/*
            do
                    echo "Processing $ff"
            done
    else
            echo "Processing $f"
    fi
done

ディレクトリとサブディレクトリを調べてすべてのファイルを一覧表示する上記のコードがあります。次のエラーが表示されます: 予期しないトークン「then」付近で構文エラーが発生しました

ここで何が間違っていますか?

4

3 に答える 3

0

これは、あなたが求めることを行う関数です。フォルダーを渡します。下部の func_process_folder_set "/folder" の呼び出しを参照してください。

    # --- -------------------------------- --- #
    # FUNC:  Process a folder of files
    # --- -------------------------------- --- #
    func_process_folder_set(){

        FOLDER="${1}"

        while read -rd $'\0' file; do

            fileext=${file##*.}  # -- get the .ext of file
            case ${fileext,,}    # -- make ext lowercase for checking in case statement
            echo "FILE: $file"   # -- print the file  (always use " " to handle file spaces)

        done < <(find  ${FOLDER} -type f -maxdepth 20 -name '*.*' -print0)

    }

    # -- call the function above with this:
    func_process_folder_set "/some/folder"
于 2014-07-15T02:12:02.907 に答える