How to initiate array element to 0 in bash?

后端 未结 3 499
有刺的猬
有刺的猬 2020-12-19 06:52
declare -a MY_ARRAY=()

Does the declaration of array in this way in bash will initiate all the array elements to 0?

If not, How to initiate

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-19 07:40

    Yes, it initiates an empty array and assigns it to MY_ARRAY. You could verify with something like this:

    #!/bin/bash
    declare -a MY_ARRAY=()
    echo ${#MY_ARRAY} # this prints out the length of the array
    

提交回复
热议问题