0

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.

1
  • the printf-part together with a command-execution and a pipe produces a formatted string consisting of the the content of the array COMMANDS that is compared to an item in an array PARAMETERS. Run the printf part separately in a shell to see what it does. What part do you have doubts about? Commented Oct 22, 2013 at 9:54

1 Answer 1

1

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 ]]?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.