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

Bash sucks at slicing arrays (always need a `[@]`):

    ${array[@]:$from:$to}
Zsh is a bit nicer:

    ${array:$from:$to}


In Bourne-descended shells, as an unfortunate historical accident, if FOO is an array, then referring to FOO without a subscript is equivalent to referring to its zeroth element.

For your example,

  ${array:$from:$to}
is equivalent to

  ${array[0]:$from:$to}
And likewise

  $ FOO=(a b c d)
  $ FOO=x
  $ echo ${FOO}
  x
  $ echo ${FOO[@]}
  x b c d




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

Search: