Reputation: 89
Inside a for loop (i) I have to test:
if [[ "${PARAMETER[$i]}" =~ $(printf "|^%s\$" "${COMMANDS[@]" | cut -c 2-)]]; then....
And my doubt is in the printf part. Sorry if it is not well explained.
Upvotes: 0
Views: 180
Reputation: 72639
The POSIX printf function works almost like its C counterpart. Here, the %s
is replaced with whatever "${COMMANDS[@]"
expands to. The result has a |^
prepended, and a $
appended.
If "${COMMANDS[@]"
expands to multiple tokens, the result is the concatenation of all such strings.
Note: did you forget a blank before the ]]
?
Upvotes: 1