Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

2
  • The array variant will break in mysterious ways if the value contains shell metacharacters. You can't quote it, either, because that prevents the shell from breaking it into multiple array elements. (I added quoting where it was missing to several answers here, including earlier in this answer.)
    – tripleee
    Commented Apr 16, 2022 at 19:21
  • 1
    @tripleee, thanks for fixing the quotes. I addressed your point and fixed my answer by changing A_array=($A) to IFS=" " read -r -d '' -a A_array <<< "$A" as a recommended "Option 2" to split the multi-word string into an array. Commented Apr 16, 2022 at 21:14