<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>Tech-Recipes - Latest Comments in bash array operations | Bourne shell scripting | Tech-Recipes</title><link>http://tech-recipes.disqus.com/</link><description>Cookbook of Tech Tutorials</description><language>en</language><lastBuildDate>Thu, 01 Oct 2009 22:13:46 -0000</lastBuildDate><item><title>Re: bash array operations | Bourne shell scripting | Tech-Recipes</title><link>http://www.tech-recipes.com/rx/910/bash-array-operations/#comment-18117581</link><description>and...here'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 "$array"="( `eval echo \$\{$array[@]:0:$i\} \$\{$array[@]:$(($i + 1))\}` )";&lt;br&gt;    else&lt;br&gt;        eval "$array"="( `eval echo \$\{$array[@]:$(($i + 1))\}` )";&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><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">DemonWeasel</dc:creator><pubDate>Thu, 01 Oct 2009 22:13:46 -0000</pubDate></item><item><title>Re: bash array operations | Bourne shell scripting | Tech-Recipes</title><link>http://www.tech-recipes.com/rx/910/bash-array-operations/#comment-18086214</link><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><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">DemonWeasel</dc:creator><pubDate>Thu, 01 Oct 2009 21:32:33 -0000</pubDate></item><item><title>Re: bash array operations | Bourne shell scripting | Tech-Recipes</title><link>http://www.tech-recipes.com/rx/910/bash-array-operations/#comment-18067848</link><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 '${'$1"[@]"'}'` )&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><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">DemonWeasel</dc:creator><pubDate>Thu, 01 Oct 2009 20:48:07 -0000</pubDate></item><item><title>Re: bash array operations | Bourne shell scripting | Tech-Recipes</title><link>http://www.tech-recipes.com/rx/910/bash-array-operations/#comment-15295017</link><description>unset command is enough</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">cori_chenxx</dc:creator><pubDate>Sun, 23 Aug 2009 21:25:03 -0000</pubDate></item><item><title>Re: bash array operations | Bourne shell scripting | Tech-Recipes</title><link>http://www.tech-recipes.com/rx/910/bash-array-operations/#comment-2769517</link><description>&lt;code&gt;#remove i from array&lt;br&gt;unset array&amp;#91;$i&amp;#93;&lt;br&gt;array=&amp;#40; $&amp;#123;array&amp;#91;@&amp;#93;&amp;#125; &amp;#41;&lt;/code&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Anonymous</dc:creator><pubDate>Fri, 29 Aug 2008 02:26:47 -0000</pubDate></item><item><title>Re: bash array operations | Bourne shell scripting | Tech-Recipes</title><link>http://www.tech-recipes.com/rx/910/bash-array-operations/#comment-2769516</link><description>so looking at the tip found here:&lt;br&gt;&lt;a href="http://www.tech-recipes.com/bourne_shell_scripting_tips910.html" rel="nofollow"&gt;http://www.tech-recipes.com/bourne_shell_script...&lt;/a&gt;&lt;br&gt;&lt;br&gt;:oops: works as long as you do not try and remove element 0. Look at just this part:&lt;br&gt;&lt;code&gt;$&amp;#123;array&amp;#91;@&amp;#93;&amp;#58;0&amp;#58;$i&amp;#125;&lt;/code&gt;&lt;br&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;&lt;br&gt; Does anyone have a better fix than this:&lt;br&gt;&lt;code&gt;#remove i from array&lt;br&gt;if &amp;#91; $i -ne 0 &amp;#93;; then&lt;br&gt;	array=&amp;#40; $&amp;#123;array&amp;#91;@&amp;#93;&amp;#58;0&amp;#58;$i&amp;#125; $&amp;#123;array&amp;#91;@&amp;#93;&amp;#58;$&amp;#40;&amp;#40;$i + 1&amp;#41;&amp;#41;&amp;#125; &amp;#41;&lt;br&gt;else&lt;br&gt;	array=&amp;#40; $&amp;#123;array&amp;#91;@&amp;#93;&amp;#58;$&amp;#40;&amp;#40;$i + 1&amp;#41;&amp;#41;&amp;#125; &amp;#41;&lt;br&gt;fi&lt;br&gt;&lt;/code&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Anonymous</dc:creator><pubDate>Sun, 25 Mar 2007 11:41:06 -0000</pubDate></item></channel></rss>