<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Tech-Recipes - Latest Comments in bash shell script iterate through array values</title><link>http://tech-recipes.disqus.com/</link><description>Cookbook of Tech Tutorials</description><atom:link href="https://tech-recipes.disqus.com/bash_shell_script_iterate_through_array_values_bourne_shell_scripting_tech_recipes/latest.rss" rel="self"></atom:link><language>en</language><lastBuildDate>Wed, 27 Jul 2011 22:30:49 -0000</lastBuildDate><item><title>Re: bash shell script iterate through array values</title><link>http://www.tech-recipes.com/rx/636/bash-shell-script-iterate-through-array-values/#comment-267198562</link><description>&lt;p&gt;I have found Notepad++ to be a great tool for Windows since it allows you to convert the line endings to Windows, Mac, or Linux while editing the file.  It also has good code highlighting.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reginald Pierce</dc:creator><pubDate>Wed, 27 Jul 2011 22:30:49 -0000</pubDate></item><item><title>Re: bash shell script iterate through array values</title><link>http://www.tech-recipes.com/rx/636/bash-shell-script-iterate-through-array-values/#comment-151909617</link><description>&lt;p&gt;Iterate through a sparse array by using:&lt;/p&gt;&lt;p&gt;ARR=([0]="zero" [1]="one" [10]="ten")&lt;br&gt;for INDEX in ${!ARR[@]}&lt;br&gt;do&lt;br&gt;   echo index $INDEX "=&amp;gt;" ${ARR[$INDEX]}&lt;br&gt;done&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jack</dc:creator><pubDate>Fri, 18 Feb 2011 19:17:08 -0000</pubDate></item><item><title>Re: bash shell script iterate through array values</title><link>http://www.tech-recipes.com/rx/636/bash-shell-script-iterate-through-array-values/#comment-150431767</link><description>&lt;p&gt;Oops., The easiest way to iterate is like you said initially., except you forgot the quotes:&lt;/p&gt;&lt;p&gt;for name in "${names[@]}"; do&lt;/p&gt;&lt;p&gt;works., and preserves the internal spaces in the elements...&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">minoc</dc:creator><pubDate>Thu, 17 Feb 2011 16:08:59 -0000</pubDate></item><item><title>Re: bash shell script iterate through array values</title><link>http://www.tech-recipes.com/rx/636/bash-shell-script-iterate-through-array-values/#comment-150426711</link><description>&lt;p&gt;as long as names are not separated by IFS (defaulting to white space).. for example&lt;/p&gt;&lt;p&gt;names=( "foo bar" "ben smith" )&lt;br&gt;for name in ${names[@]}; do echo "[${name}]"; done&lt;br&gt;[foo]&lt;br&gt;[bar]&lt;br&gt;[ben]&lt;br&gt;[smith]&lt;/p&gt;&lt;p&gt;whereas this preserves the spacing in array elements:&lt;/p&gt;&lt;p&gt;for ((i=0; i&amp;lt;${#names[@]}; i++)); do echo "[${names[${i}]}]"; done&lt;br&gt;[foo bar]&lt;br&gt;[ben smith]&lt;/p&gt;&lt;p&gt;I am not yet sure how to iterate thru a sparse array yet... &lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">minoc</dc:creator><pubDate>Thu, 17 Feb 2011 16:02:52 -0000</pubDate></item><item><title>Re: bash shell script iterate through array values</title><link>http://www.tech-recipes.com/rx/636/bash-shell-script-iterate-through-array-values/#comment-142558903</link><description>&lt;p&gt;it works perfectly&lt;/p&gt;&lt;p&gt;Thanks a lot&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">sriram</dc:creator><pubDate>Tue, 08 Feb 2011 08:36:10 -0000</pubDate></item><item><title>Re: bash shell script iterate through array values</title><link>http://www.tech-recipes.com/rx/636/bash-shell-script-iterate-through-array-values/#comment-94593022</link><description>&lt;p&gt;great!...&lt;br&gt;i really need this &lt;br&gt; thanks&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">annie</dc:creator><pubDate>Sat, 06 Nov 2010 15:25:26 -0000</pubDate></item><item><title>Re: bash shell script iterate through array values</title><link>http://www.tech-recipes.com/rx/636/bash-shell-script-iterate-through-array-values/#comment-51974463</link><description>&lt;p&gt;Thanks for the for function m8, you just saved me some hours.&lt;br&gt;Now I can get back to my Script. You guys can also place the 'do' on the first line&lt;br&gt;IMHO it looks better this way.&lt;/p&gt;&lt;p&gt;for name in ${names[@]}; do&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Thanish</dc:creator><pubDate>Tue, 25 May 2010 13:43:40 -0000</pubDate></item><item><title>Re: bash shell script iterate through array values</title><link>http://www.tech-recipes.com/rx/636/bash-shell-script-iterate-through-array-values/#comment-49167529</link><description>&lt;p&gt;Right, I've forgot to mention that option too&lt;br&gt;If you are working on Ubuntu, like me, then the package "tofrodos" contains the dos2unix utility.&lt;br&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">TuxSax</dc:creator><pubDate>Sun, 09 May 2010 02:36:18 -0000</pubDate></item><item><title>Re: bash shell script iterate through array values</title><link>http://www.tech-recipes.com/rx/636/bash-shell-script-iterate-through-array-values/#comment-29325634</link><description>&lt;p&gt;Thanks a lot..&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">JassTheFabulous</dc:creator><pubDate>Mon, 11 Jan 2010 02:01:23 -0000</pubDate></item><item><title>Re: bash shell script iterate through array values</title><link>http://www.tech-recipes.com/rx/636/bash-shell-script-iterate-through-array-values/#comment-17919986</link><description>&lt;p&gt;I had a similar problem until I realized that the file I was working on was created on Windows too.&lt;br&gt;I fixed it with:&lt;br&gt;sed -i 's/\r$//' &amp;lt;file&amp;gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">TuxSax</dc:creator><pubDate>Thu, 01 Oct 2009 04:19:01 -0000</pubDate></item><item><title>Re: bash shell script iterate through array values</title><link>http://www.tech-recipes.com/rx/636/bash-shell-script-iterate-through-array-values/#comment-9048768</link><description>&lt;p&gt;thnx a lot pal &lt;br&gt;I owe u 5 marks of my final exam &lt;br&gt;:)&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">kool</dc:creator><pubDate>Wed, 06 May 2009 02:53:04 -0000</pubDate></item><item><title>Re: bash shell script iterate through array values</title><link>http://www.tech-recipes.com/rx/636/bash-shell-script-iterate-through-array-values/#comment-6598986</link><description>&lt;p&gt;Thank you very much for this snipped - just what I was looking for!&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Olly</dc:creator><pubDate>Wed, 25 Feb 2009 08:38:28 -0000</pubDate></item><item><title>Re: bash shell script iterate through array values</title><link>http://www.tech-recipes.com/rx/636/bash-shell-script-iterate-through-array-values/#comment-6583158</link><description>&lt;p&gt;if you really have to use windows, then cygwin is your salvation.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">mati</dc:creator><pubDate>Tue, 24 Feb 2009 19:02:43 -0000</pubDate></item><item><title>Re: bash shell script iterate through array values</title><link>http://www.tech-recipes.com/rx/636/bash-shell-script-iterate-through-array-values/#comment-6181098</link><description>&lt;p&gt;ah, just what I was looking for - perfect, thanks!&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">JamesDS</dc:creator><pubDate>Wed, 11 Feb 2009 12:32:08 -0000</pubDate></item><item><title>Re: bash shell script iterate through array values</title><link>http://www.tech-recipes.com/rx/636/bash-shell-script-iterate-through-array-values/#comment-5869274</link><description>&lt;p&gt;The reason for this error is that the control character sequence used by DOS (Windows, \r\n) is different from the sequnce used by UNIX (*NIX, \n)&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">RobbyC</dc:creator><pubDate>Thu, 05 Feb 2009 12:03:00 -0000</pubDate></item><item><title>Re: bash shell script iterate through array values</title><link>http://www.tech-recipes.com/rx/636/bash-shell-script-iterate-through-array-values/#comment-4009529</link><description>&lt;p&gt;all kinds of errors will popup if you write this (or any) script on windows. i was almost giving up when i realised i had written it on notepad and saved on the linux box over samba. use dostounix &amp;lt;scriptfile&amp;gt; to fix the format.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Fakeer</dc:creator><pubDate>Tue, 25 Nov 2008 13:48:30 -0000</pubDate></item></channel></rss>