Linda Walsh schreef op 16-02-16 om 04:59: > w/the slow func being killed by a $() sub process, likely:
Yes, subshells are fatal for performance, particularly on bash. > my fn2='() { my t="${2:?}[*]" > my arRE="^($(IFS="|"; echo "${!t}"))$" > [[ $1 =~ $arRE ]] > } > ' (What's "my"? An alias for "local"?) Try this: appears_in() { local IFS="|" val="$1" shift [[ "$IFS$*$IFS" == *"$IFS$val$IFS"* ]] } if appears_in "somevalue" "${array[@]}"; then do stuff; fi For anyone reading who may not know, the trick is that "$*" expands to a single string containing all the positional parameters separated by the first character of $IFS (or with no separator if IFS is empty, but that's not useful here). Of course this function is dependent on none of the elements containing "|". But this lets you set any separator you want, so you could use a really unlikely character such as IFS=$'\1'. - M.