Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

"${stuff[@]}" expands into the elements of the array, with each one quoted - so even that first "foo foo" element with a space will be handled correctly. That is how I would write the loop as well, in general.

However, your technique also works, with some tweaks:

* The loop goes one index too far, and can be fixed with seq 0 $(( array_length - 1 ))

* There should be quotes around ${stuff[i]} in case it has spaces



Oh, that's way better for sure! Thanks for the explanation




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: