From ab8bae17785ff437d4758f1fb123e2b544b4ca2e Mon Sep 17 00:00:00 2001 From: Chris Koeritz Date: Sun, 29 Sep 2013 20:24:54 -0500 Subject: [PATCH] new example for bash. --- examples/bashisms/comma_separated_string_to_array.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 examples/bashisms/comma_separated_string_to_array.sh diff --git a/examples/bashisms/comma_separated_string_to_array.sh b/examples/bashisms/comma_separated_string_to_array.sh new file mode 100644 index 00000000..64c05b3e --- /dev/null +++ b/examples/bashisms/comma_separated_string_to_array.sh @@ -0,0 +1,12 @@ + + +#taking a comma (or any char) separated list and turning it into an array: + +commaSeparatedList=tony,tiger,detroit,sugar,biscuits + +IFS="," read -ra argArray <<< "$commaSeparatedList" + +for ((i = 0; i < ${#argArray[@]}; i++)); do + echo "arg $(($i + 1)): ${argArray[$i]}" +done + -- 2.34.1