Link to home
Start Free TrialLog in
Avatar of enthuguy
enthuguyFlag for Australia

asked on

How to check if directory exist using asterisk in Bash

Hi Experts,
could you pls help me how to check if directory exist using asterisk "*" in bash "if condition".
Basically would like to check if directory exist like *Drop* or best solution please

Below is the sample script
cd /home/mobaxterm; mkdir tmp tmp1  Child_Drop1 Child_Drop2 Child_Drop3 Child_Drop4 Child_Drop5

base=/home/mobaxterm/tmp
base_dir="${base}/*Drop*"

ls -ltr "${base}/"*Drop*
cp -r  "${base}/"*Drop* ${base}/tmp1/

if [ -d "${base_dir}" ] ; then
  echo "drop exists"
  cp -r  "${base}/"*Drop* ${base}/tmp1/
else
  echo "drop do not exists"
fi

Open in new window


Thanks in advance
SOLUTION
Avatar of Ricardo Canani
Ricardo Canani
Flag of Brazil image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of noci
noci

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial