<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: bash array operations</title>
	<atom:link href="http://www.tech-recipes.com/rx/910/bash-array-operations/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tech-recipes.com/rx/910/bash-array-operations/</link>
	<description>Computer and technology tutorials and guides</description>
	<lastBuildDate>Sat, 21 Nov 2009 16:14:40 -0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: DemonWeasel</title>
		<link>http://www.tech-recipes.com/rx/910/bash-array-operations/comment-page-1/#comment-15371</link>
		<dc:creator>DemonWeasel</dc:creator>
		<pubDate>Fri, 02 Oct 2009 00:13:46 +0000</pubDate>
		<guid isPermaLink="false">guid-fix-me!#comment-15371</guid>
		<description>and...here&#039;s the real solution...&lt;br&gt;&lt;br&gt;function remel() {&lt;br&gt;    array=$1&lt;br&gt;    i=$2&lt;br&gt;    if [ $i -ne 0 ]; then&lt;br&gt;        eval &quot;$array&quot;=&quot;( `eval echo ${$array[@]:0:$i} ${$array[@]:$(($i + 1))}` )&quot;;&lt;br&gt;    else&lt;br&gt;        eval &quot;$array&quot;=&quot;( `eval echo ${$array[@]:$(($i + 1))}` )&quot;;&lt;br&gt;    fi&lt;br&gt;}&lt;br&gt;&lt;br&gt;#to use it:&lt;br&gt;arr=( a b c d )&lt;br&gt;echo ${arr[@]}&lt;br&gt;echo ${arr[1]}&lt;br&gt;#now it actually just removes the element...&lt;br&gt;remel arr 1&lt;br&gt;echo ${arr[@]}&lt;br&gt;echo ${arr[1]}</description>
		<content:encoded><![CDATA[<p>and&#8230;here&#39;s the real solution&#8230;</p>
<p>function remel() {<br />    array=$1<br />    i=$2<br />    if [ $i -ne 0 ]; then<br />        eval &#8220;$array&#8221;=&#8221;( `eval echo ${$array[@]:0:$i} ${$array[@]:$(($i + 1))}` )&#8221;;<br />    else<br />        eval &#8220;$array&#8221;=&#8221;( `eval echo ${$array[@]:$(($i + 1))}` )&#8221;;<br />    fi<br />}</p>
<p>#to use it:<br />arr=( a b c d )<br />echo ${arr[@]}<br />echo ${arr[1]}<br />#now it actually just removes the element&#8230;<br />remel arr 1<br />echo ${arr[@]}<br />echo ${arr[1]}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: DemonWeasel</title>
		<link>http://www.tech-recipes.com/rx/910/bash-array-operations/comment-page-1/#comment-15370</link>
		<dc:creator>DemonWeasel</dc:creator>
		<pubDate>Thu, 01 Oct 2009 23:32:33 +0000</pubDate>
		<guid isPermaLink="false">guid-fix-me!#comment-15370</guid>
		<description>or if you want a more standard syntax of taking an array in as a parameter&lt;br&gt;&lt;br&gt;function remel(){&lt;br&gt;    array=( $@ )&lt;br&gt;    let ind=${#array[@]}-1&lt;br&gt;    i=${array[$ind]}&lt;br&gt;    unset array[$ind]&lt;br&gt;    if [ $i -ne 0 ]; then&lt;br&gt;        array=( ${array[@]:0:$i} ${array[@]:$(($i + 1))} )&lt;br&gt;    else&lt;br&gt;        array=( ${array[@]:$(($i + 1))} )&lt;br&gt;    fi&lt;br&gt;    echo ${array[@]}&lt;br&gt;}&lt;br&gt;&lt;br&gt;#to use it:&lt;br&gt;arr=( a b c d )&lt;br&gt;echo ${arr[@]}&lt;br&gt;echo ${arr[1]}&lt;br&gt;#to remove element 1 set the array equal to an array of the output&lt;br&gt;arr=( `remel ${arr[@]} 1` )&lt;br&gt;echo ${arr[@]}&lt;br&gt;echo ${arr[1]}</description>
		<content:encoded><![CDATA[<p>or if you want a more standard syntax of taking an array in as a parameter</p>
<p>function remel(){<br />    array=( $@ )<br />    let ind=${#array[@]}-1<br />    i=${array[$ind]}<br />    unset array[$ind]<br />    if [ $i -ne 0 ]; then<br />        array=( ${array[@]:0:$i} ${array[@]:$(($i + 1))} )<br />    else<br />        array=( ${array[@]:$(($i + 1))} )<br />    fi<br />    echo ${array[@]}<br />}</p>
<p>#to use it:<br />arr=( a b c d )<br />echo ${arr[@]}<br />echo ${arr[1]}<br />#to remove element 1 set the array equal to an array of the output<br />arr=( `remel ${arr[@]} 1` )<br />echo ${arr[@]}<br />echo ${arr[1]}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: DemonWeasel</title>
		<link>http://www.tech-recipes.com/rx/910/bash-array-operations/comment-page-1/#comment-15369</link>
		<dc:creator>DemonWeasel</dc:creator>
		<pubDate>Thu, 01 Oct 2009 22:48:07 +0000</pubDate>
		<guid isPermaLink="false">guid-fix-me!#comment-15369</guid>
		<description>#a function to create a new array minus the specified element&lt;br&gt;&lt;br&gt;function remel() {&lt;br&gt;    array=( `eval echo &#039;${&#039;$1&quot;[@]&quot;&#039;}&#039;` )&lt;br&gt;    i=$2&lt;br&gt;    #remove EL from array&lt;br&gt;    if [ $i -ne 0 ]; then&lt;br&gt;        array=( ${array[@]:0:$i} ${array[@]:$(($i + 1))} )&lt;br&gt;    else&lt;br&gt;        array=( ${array[@]:$(($i + 1))} )&lt;br&gt;    fi&lt;br&gt;    echo ${array[@]}&lt;br&gt;}&lt;br&gt;&lt;br&gt;#to use it:&lt;br&gt;arr=( a b c d )&lt;br&gt;echo ${arr[@]}&lt;br&gt;echo ${arr[1]}&lt;br&gt;#to remove element 1 set the array equal to an array of the output&lt;br&gt;arr=( `remel arr 1` )&lt;br&gt;echo ${arr[@]}&lt;br&gt;echo ${arr[1]}</description>
		<content:encoded><![CDATA[<p>#a function to create a new array minus the specified element</p>
<p>function remel() {<br />    array=( `eval echo &#39;${&#39;$1&#8243;[@]&#8220;&#39;}&#39;` )<br />    i=$2<br />    #remove EL from array<br />    if [ $i -ne 0 ]; then<br />        array=( ${array[@]:0:$i} ${array[@]:$(($i + 1))} )<br />    else<br />        array=( ${array[@]:$(($i + 1))} )<br />    fi<br />    echo ${array[@]}<br />}</p>
<p>#to use it:<br />arr=( a b c d )<br />echo ${arr[@]}<br />echo ${arr[1]}<br />#to remove element 1 set the array equal to an array of the output<br />arr=( `remel arr 1` )<br />echo ${arr[@]}<br />echo ${arr[1]}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cori_chenxx</title>
		<link>http://www.tech-recipes.com/rx/910/bash-array-operations/comment-page-1/#comment-14481</link>
		<dc:creator>cori_chenxx</dc:creator>
		<pubDate>Sun, 23 Aug 2009 23:25:03 +0000</pubDate>
		<guid isPermaLink="false">guid-fix-me!#comment-14481</guid>
		<description>unset command is enough</description>
		<content:encoded><![CDATA[<p>unset command is enough</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: </title>
		<link>http://www.tech-recipes.com/rx/910/bash-array-operations/comment-page-1/#comment-3695</link>
		<dc:creator></dc:creator>
		<pubDate>Fri, 29 Aug 2008 06:26:47 +0000</pubDate>
		<guid isPermaLink="false">guid-fix-me!#comment-3695</guid>
		<description>&lt;code&gt;#remove i from array
unset array&#91;$i&#93;
array=&#40; $&#123;array&#91;@&#93;&#125; &#41;&lt;/code&gt;
</description>
		<content:encoded><![CDATA[<p><code>#remove i from array<br />
unset array&#91;$i&#93;<br />
array=&#40; $&#123;array&#91;@&#93;&#125; &#41;</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: </title>
		<link>http://www.tech-recipes.com/rx/910/bash-array-operations/comment-page-1/#comment-3328</link>
		<dc:creator></dc:creator>
		<pubDate>Sun, 25 Mar 2007 15:41:06 +0000</pubDate>
		<guid isPermaLink="false">guid-fix-me!#comment-3328</guid>
		<description>so looking at the tip found here:
http://www.tech-recipes.com/bourne_shell_scripting_tips910.html

:oops: works as long as you do not try and remove element 0. Look at just this part:
&lt;code&gt;$&#123;array&#91;@&#93;&#58;0&#58;$i&#125;&lt;/code&gt;
 and you will notice the array is rebuilt using items 0 through $i. The 0 will cause element 0 to stay in the array even if &lt;code&gt; i=0&lt;/code&gt;
 Does anyone have a better fix than this:
&lt;code&gt;#remove i from array
if &#91; $i -ne 0 &#93;; then
	array=&#40; $&#123;array&#91;@&#93;&#58;0&#58;$i&#125; $&#123;array&#91;@&#93;&#58;$&#40;&#40;$i + 1&#41;&#41;&#125; &#41;
else
	array=&#40; $&#123;array&#91;@&#93;&#58;$&#40;&#40;$i + 1&#41;&#41;&#125; &#41;
fi
&lt;/code&gt;
</description>
		<content:encoded><![CDATA[<p>so looking at the tip found here:<br />
<a href="http://www.tech-recipes.com/bourne_shell_scripting_tips910.html" rel="nofollow">http://www.tech-recipes.com/bourne_shell_scripting_tips910.html</a></p>
<p>:oops: works as long as you do not try and remove element 0. Look at just this part:<br />
<code>$&#123;array&#91;@&#93;&#58;0&#58;$i&#125;</code><br />
 and you will notice the array is rebuilt using items 0 through $i. The 0 will cause element 0 to stay in the array even if <code> i=0</code><br />
 Does anyone have a better fix than this:<br />
<code>#remove i from array<br />
if &#91; $i -ne 0 &#93;; then<br />
	array=&#40; $&#123;array&#91;@&#93;&#58;0&#58;$i&#125; $&#123;array&#91;@&#93;&#58;$&#40;&#40;$i + 1&#41;&#41;&#125; &#41;<br />
else<br />
	array=&#40; $&#123;array&#91;@&#93;&#58;$&#40;&#40;$i + 1&#41;&#41;&#125; &#41;<br />
fi<br />
</code></p>
]]></content:encoded>
	</item>
</channel>
</rss>
