Many wonderful comments have already been given. Here are some nitpicks that will no longer matter once you stop writing this program in bash, which is a poor choice for this particular job.
On Sat, Jun 20, 2020 at 12:20:41PM +0200, Albretch Mueller wrote: > for iZ in ${!_AR_TERMS[@]}; do The quoting here is incorrect. It should be: for iZ in "${!_ar_terms[@]}"; do You probably got away with it because you haven't used indices that contain whitespace yet. (I'm not even sure whether you're using an indexed array, or an associative array. Obviously with indexed arrays, your indices are always integers, so the improper quoting won't be able to bite you -- but that changes as soon as you use an associative array where the indices can be arbitrary strings.) Also, do not use all-caps variable names for regular variables. All-caps names are reserved for environment variables and special internal shell variables. Use at least one lower case letter in each variable to avoid collisions with reserved names. > find "${_SDIR}" -type f -iregex .*"${_X}" -exec grep -il Here, the .* (or at least the *) should be quoted too. Otherwise, the * is part of a live glob that could potentially match filenames in the current working directory, which would break the script. unicorn:~$ x=rc unicorn:~$ args find . -iregex .*"$x" 47 args: <find> <.> <-iregex> <.acrorc> <.aumixrc> <.avirc> <.bashrc> <.bwaprc> <.cdrrc> <.ceciliarc> <.civclientrc> <.dialogrc> <.doomrc> <.dvdriprc> <.exrc> <.fehrc> <.fvwm2rc> <.gnomerc> <.inputrc> <.ircrc> <.jnewsrc> <.kderc> <.kermrc> <.lessrc> <.lynxrc> <.mangrc> <.mcoprc> <.micqrc> <.mp3capnrc> <.mp3commanderrc> <.muttrc> <.newsrc> <.oldnewsrc> <.pinerc> <.point2playrc> <.ppprc> <.qwebrc> <.reportbugrc> <.rtorrent.rc> <.slrnrc> <.twinrc> <.twmrc> <.vimrc> <.xfmailrc> <.xinitrc> <.xmodmaprc> <.zshrc> That's definitely NOT what you want. unicorn:~$ args find . -iregex ".*$x" 4 args: <find> <.> <-iregex> <.*rc> That's what you want.