[重複]ディレクトリに複数のファイルがあることを確認してください。

[重複]ディレクトリに複数のファイルがあることを確認してください。

ディレクトリ内の複数のファイルを見つける方法ksh(パート1 AIX

次のいずれかを試しています。

if [ $# -lt 1 ];then
    echo "Please enter the path"
    exit
fi
path=$1
if [ [ ! f $path/cc*.csv ] && [ ! f $path/cc*.rpt ] && [ ! f $path/*.xls ] ];then
    echo "All required files are not present\n"
fi

check[6]: !: unknown test operator//check is my filename などのエラーが発生します。

私のスクリプトに何の問題がありますか?誰でもこの問題を解決するのに役立ちますか?

ベストアンサー1

test -fワイルドカードで拡張された複数のファイルでは機能しません。代わりに、null-redirectedでシェル関数を使用できますls

present() {
        ls "$@" >/dev/null 2>&1
}

if [ $# -lt 1 ]; then
    echo "Please enter the path"
    exit
fi
path=$1
if ! present $path/cc*.csv && ! present $path/cc*.rpt && ! present $path/*.xls; then
    echo "All required files are not present\n"
fi

しかし、使用するのは良いですか&&?この場合、またはまたはnot presentという名前のファイルがない場合にのみ取得できます。cc*.csvcc*.rptcc*.xls$path

おすすめ記事