<?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>Thu, 09 Feb 2012 21:01:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</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-34871</link>
		<dc:creator>DemonWeasel</dc:creator>
		<pubDate>Fri, 02 Oct 2009 02:13:00 +0000</pubDate>
		<guid isPermaLink="false">guid-fix-me!#comment-34871</guid>
		<description>and...here&#039;s the real solution...

function remel() {
    array=$1
    i=$2
    if [ $i -ne 0 ]; then
        eval &quot;$array&quot;=&quot;( `eval echo ${$array[@]:0:$i} ${$array[@]:$(($i + 1))}` )&quot;;
    else
        eval &quot;$array&quot;=&quot;( `eval echo ${$array[@]:$(($i + 1))}` )&quot;;
    fi
}

#to use it:
arr=( a b c d )
echo ${arr[@]}
echo ${arr[1]}
#now it actually just removes the element...
remel arr 1
echo ${arr[@]}
echo ${arr[1]}</description>
		<content:encoded><![CDATA[<p>and&#8230;here&#8217;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-34870</link>
		<dc:creator>DemonWeasel</dc:creator>
		<pubDate>Fri, 02 Oct 2009 01:32:00 +0000</pubDate>
		<guid isPermaLink="false">guid-fix-me!#comment-34870</guid>
		<description>or if you want a more standard syntax of taking an array in as a parameter

function remel(){
    array=( $@ )
    let ind=${#array[@]}-1
    i=${array[$ind]}
    unset array[$ind]
    if [ $i -ne 0 ]; then
        array=( ${array[@]:0:$i} ${array[@]:$(($i + 1))} )
    else
        array=( ${array[@]:$(($i + 1))} )
    fi
    echo ${array[@]}
}

#to use it:
arr=( a b c d )
echo ${arr[@]}
echo ${arr[1]}
#to remove element 1 set the array equal to an array of the output
arr=( `remel ${arr[@]} 1` )
echo ${arr[@]}
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-34869</link>
		<dc:creator>DemonWeasel</dc:creator>
		<pubDate>Fri, 02 Oct 2009 00:48:00 +0000</pubDate>
		<guid isPermaLink="false">guid-fix-me!#comment-34869</guid>
		<description>#a function to create a new array minus the specified element

function remel() {
    array=( `eval echo &#039;${&#039;$1&quot;[@]&quot;&#039;}&#039;` )
    i=$2
    #remove EL from array
    if [ $i -ne 0 ]; then
        array=( ${array[@]:0:$i} ${array[@]:$(($i + 1))} )
    else
        array=( ${array[@]:$(($i + 1))} )
    fi
    echo ${array[@]}
}

#to use it:
arr=( a b c d )
echo ${arr[@]}
echo ${arr[1]}
#to remove element 1 set the array equal to an array of the output
arr=( `remel arr 1` )
echo ${arr[@]}
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 &#8216;${&#8216;$1&#8243;[@]&#8220;&#8216;}&#8217;` )<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: Anonymous</title>
		<link>http://www.tech-recipes.com/rx/910/bash-array-operations/comment-page-1/#comment-32798</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Mon, 24 Aug 2009 01:25:00 +0000</pubDate>
		<guid isPermaLink="false">guid-fix-me!#comment-32798</guid>
		<description>unset command is enough</description>
		<content:encoded><![CDATA[<p>unset command is enough</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached (User agent is rejected)
Database Caching 2/11 queries in 0.726 seconds using memcached
Object Caching 307/311 objects using memcached

Served from: www.tech-recipes.com @ 2012-02-10 00:11:02 -->
