troubleshooting Question

how to get directory names in a list and perform rm safely using shell

Avatar of enthuguy
enthuguyFlag for Australia asked on
LinuxShell ScriptingSystem Programming
7 Comments3 Solutions173 ViewsLast Modified:
would request your advise on this pls

I have a couple of directories with bunch of sub directories in date format

directory name :

would like to delete some directories by accepting date range in comma separated and delete only those directories.
e.g 2016-09-11,2016-09-13,2016-09-15

so outcome after delete would be

I can hard code the base directory to be safe e.g

 for currentDt in $(echo ${date_range} | sed "s/,/ /g")
	if ([ "${currentDt}" != "" ] || [ "${currentDt}" != "*" ]); then
		# is this enough? or can we add some more validation ?
		# rm -Rf  ${base_dir}/${currentDt}

pls help is there any strong validation that I can perform. or a better way to handle this.

thanks in advance

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 3 Answers and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros