new example for bash.
authorChris Koeritz <fred@gruntose.com>
Mon, 30 Sep 2013 01:24:54 +0000 (20:24 -0500)
committerChris Koeritz <fred@gruntose.com>
Mon, 30 Sep 2013 01:24:54 +0000 (20:24 -0500)
examples/bashisms/comma_separated_string_to_array.sh [new file with mode: 0644]

diff --git a/examples/bashisms/comma_separated_string_to_array.sh b/examples/bashisms/comma_separated_string_to_array.sh
new file mode 100644 (file)
index 0000000..64c05b3
--- /dev/null
@@ -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
+