Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

let unset array element remove compatible with bash



As we know, bash is very common on Linux world.
So, even I've moved to zsh.
But, I wish my script could be compatible with bash.

Today, I found the array element remove is not compatible with bash.
Can any developer consider to enhance zsh's function like "unset var[2]"?

Here is the sample


  $var[1]="four" ; var[2]="seven" ; var[3]="Four and
Seven"
  $for v in "${var[@]}" ; do echo "$v" ;
done

four


seven

  Four and
Seven
  $for v in "${var[*]}" ; do echo "$v" ;
done
  four seven Four and
Seven
  $echo "${#var[@]} ${#var[1]} ${#var[2]} ${#var[3]}"  # get
lengh
  3 4 5
14
  $unset var[2] ###### BASH only delete one
element
  $var[2]=() ###### ZSH only delete one
element
  $echo "${#var[@]} ${#var[1]} ${#var[2]}
${#var[3]}"
  2 4 0 14

Another note, I wish the FAQ in zsh can explain this incompatible with bash.

$echo "${#var[@]} ${#var[1]} ${#var[2]} ${#var[3]}"  # get lengh  work both
bash/zsh
$echo "$#var $#var[1] $#var[2] $#var[3]"  # get lengh  work only zsh


Messages sorted by: Reverse Date, Date, Thread, Author