我写了一些应该在父目录中找到目录的函数,但问题是它需要很长时间,可能它也在子目录中搜索。这是我的代码:
function findMspDir () {
mountedDir=/opt/SwDrop/
dirToSearch=/opt/SwDrop/Repository/
if [ ! -d $mountedDir ]; then
echo "The directory hasn't been found"
exit 1;
else
echo "The directory is mounted"
subDirToSearch="MSP-$versionNum"
# mspDir=`find $dirToSearch -name $subDirToSearch`
mspDir=$(find /opt/SwDrop/Repository/ -name 'MSP-1.5.1.4')
if [ "$mspDir" = "" ]; then
echo "The MSP directory hasn't been found"
exit 1;
fi
fi
echo "The found directory is: $mspDir"
}
我确定我要查找的目录位于/opt/SwDrop/Repository/
其下且不能位于子目录中。知道如何解决吗?