I have a script which I want to go over 4 sets of files PURO*.xml, PURR*.xml, SALO*.xml and SALR*.xml.
for j in PUR SAL
do
mask=("${j}O*.xml" "${j}R*.xml")
for k in 0 1
do
for file in `find ${CDIR} -maxdepth 1 -daystart -mtime ${MTIME} -and -name ${mask[$k]} | xargs`
The script works, however, when it is executed, if the working directory has files that match one of the mask, that mask gets expanded.
Question is, what would be the correct way to write the above piece of script so that mask is passed correctly to find command? I want "${j}" expanded at the point where I create mask, but not the "*".
Also, is backticked find OK or should I perhaps rewrite that part differently as well?
find
command. Also consider letting thefind
command use-exec
instead of looping over its output (see "Why is looping over find's output bad practice?"). – Kusalananda Jan 11 '19 at 09:38$(...)
instead on backticks. See What is the benefit of using $() instead of backticks in shell scripts?. – Ralf Jan 11 '19 at 10:42