DISQUS

DISQUS Hello! Tech-Recipes is using DISQUS, a powerful comment system, to manage its comments. Learn more.

Community Page

Tech-Recipes

Cookbook of Tech Tutorials
Jump to original thread »
Author

bash array operations | Bourne shell scripting | Tech-Recipes

Started by qdideas · 9 months ago

No excerpt available. Jump to website »

2 comments

  • so looking at the tip found here:
    http://www.tech-recipes.com/bourne_shell_script...

    :oops: works as long as you do not try and remove element 0. Look at just this part:
    ${array[@]:0:$i}
    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 i=0
    Does anyone have a better fix than this:
    #remove i from array
    if [ $i -ne 0 ]; then
    array=( ${array[@]:0:$i} ${array[@]:$(($i + 1))} )
    else
    array=( ${array[@]:$(($i + 1))} )
    fi
  • #remove i from array
    unset array[$i]
    array=( ${array[@]} )

Add New Comment

Returning? Login