X-Git-Url: https://feistymeow.org/gitweb/?a=blobdiff_plain;f=examples%2Fbashisms%2Fcomma_separated_string_to_array.sh;fp=examples%2Fbashisms%2Fcomma_separated_string_to_array.sh;h=64c05b3e9032f19a480d3924c4bb53ba99c77f0c;hb=ab8bae17785ff437d4758f1fb123e2b544b4ca2e;hp=0000000000000000000000000000000000000000;hpb=0d77851abf1f2f53905c04aa9b17c1d076f0ce36;p=feisty_meow.git 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 +