bash脚本-如何检查以开头的目录是否存在

bash脚本-如何检查以开头的目录是否存在,bash,macos,Bash,Macos,我一直在尝试写一个脚本: EFIDIR=/Volumes/EFI KEXTDEST=$EFIDIR/EFI/CLOVER/kexts/Other if [[ -d $EFIDIR/EFI/CLOVER/kexts/10.* ]]; then echo "Directory found." if [[ -d $EFIDIR/EFI/CLOVER/kexts/10.*/*.kext ]]; then echo "Kext(s) found." cp

我一直在尝试写一个脚本:

EFIDIR=/Volumes/EFI
KEXTDEST=$EFIDIR/EFI/CLOVER/kexts/Other

if [[ -d $EFIDIR/EFI/CLOVER/kexts/10.* ]]; then
    echo "Directory found."
    if [[ -d $EFIDIR/EFI/CLOVER/kexts/10.*/*.kext ]]; then
        echo "Kext(s) found."
        cp -R $EFIDIR/EFI/CLOVER/kexts/10.*/*.kext $KEXTDEST
    fi
    rm -R $EFIDIR/EFI/CLOVER/kexts/10.*
fi
我想检查是否存在任何以“10”开头的文件夹(可以是10.10、10.11…等等),然后如果这些文件夹中有任何文件夹包含以(.kext)结尾的文件夹,则是否存在。。。复制到目标文件夹

如何用正确的方式书写

谢谢。

试试这个:

EFIDIR=/Volumes/EFI
KEXTDEST=$EFIDIR/EFI/CLOVER/kexts/Other

for each in $(find $EFIDIR/EFI/CLOVER/kexts/ -name "10.*" -type d); do
    echo "Directory found."
    for innerdir in $(find $each -name "*.kext" -type d); do
        echo "Kext(s) found."
        cp -R $innerdir $KEXTDEST
    done
    rm -R $each
done
find$EFIDIR/EFI/CLOVER/kexts/-name“10.*”-类型d
将在
$EFIDIR/EFI/CLOVER/kexts
中查找以名称
10.*
开头的目录(
-type d
),如果找到,将遍历
for
循环中的每个目录

的内部
循环查找以名称开头的目录。kext

尝试以下操作:

EFIDIR=/Volumes/EFI
KEXTDEST=$EFIDIR/EFI/CLOVER/kexts/Other

for each in $(find $EFIDIR/EFI/CLOVER/kexts/ -name "10.*" -type d); do
    echo "Directory found."
    for innerdir in $(find $each -name "*.kext" -type d); do
        echo "Kext(s) found."
        cp -R $innerdir $KEXTDEST
    done
    rm -R $each
done
find$EFIDIR/EFI/CLOVER/kexts/-name“10.*”-类型d
将在
$EFIDIR/EFI/CLOVER/kexts
中查找以名称
10.*
开头的目录(
-type d
),如果找到,将遍历
for
循环中的每个目录

的内部
循环查找以name
*.kext
开头的目录