I'm currently using this code:
target_directory_greater="/root/*/"
if [ "${target_directory}" != "${target_directory%%\***}" ]; then
base_target_directory="${target_directory%%\***}"
prefix_target_directory="${target_directory##**\*}"
for t in $base_target_directory/* ; do
if [ -d "${t}${prefix_target_directory}" ]; then
# Found, replace target_directory with real path
target_directory="${t}${prefix_target_directory}"
break
else
continue
fi
done
fi
if [ ! -d "${target_directory}" ]; then
printf "${target_directory} directory wasn't found.\\n\\n"
exit 1
fi
My script will move two folders if grep finds the correct folder which it does. Once grep finds the correct folder for the files to move to, that code above kicks in to process the *
character in my declared variable and it simply just uses the first folder instead of the one grep pointed to. Does anyone see my mistake there?
/root
folder has a few other randomly named folders inside there and I use grep to grab a specific string and then move the files solely to that folder. But since there's a *
, it's causing issues.