Hello,
I want to check if directories exist with a regex expression
dir1=/temp/local/*/home (exists on file system)
dir2=/temp/server/*/logs (does not exist on file system)
I want to check if there are any directories with the above regex
Code:
if [[ -d ${dir} ]];then
echo "Directory exist"
else
echo "Directory does not exist"
fi
For both dir1 and dir2 "Directory does not exist" is printed.
Any way to make this check.
Thanks
if [ `find ${dir} -type d -prune` ]; then
echo "Directory exist"
else
echo "Directory does not exist"
fi
Using only basic sh and printing a line for each match found:
for d in /temp/local/*/home/ /temp/server/*/logs/; do
if [ -d "$d" ]; then
echo "$d: exists"
else
echo "$d: no match"
fi
done
Regards,
Alister
1 Like
ctsgnb
April 11, 2011, 1:10pm
4
Or just
ls -d /temp/local/*/home /temp/server/*/logs
... but ok i know what you guys are going to say :
.... argument list too long & MAX_ARGS constraints ...
Stick with alister's suggestion, that's the best one (... the suggestion )
Sticking too many args in a for statement doesn't make too many args not be too many args. Neither does sticking 'find' in backticks make too many args not be too many args.
Just searching for directory names though, I don't think is likely to cause too many arguments.