Bash: Split String

You can’t use arrays as env vars.

You can’t pass an array to a bash script.

You can pass a delimited string and then let bash split it into an array.

#!/usr/bin/env bash

STRING="one two three four"

echo "STRING: $STRING"

# Use parameter expansion
# ${PARAMETER//PATTERN/STRING}
# // means replace all
ARR=(${STRING// / })

echo "ARR: ${ARR[*]}"

for value in ${ARR[*]}; do
  echo "value: $value"
done