Using unset vs. setting a variable to empty

前端 未结 4 1093
一生所求
一生所求 2020-12-23 00:37

I\'m currently writing a bash testing framework, where in a test function, both standard bash tests ([[) as well as predefined matchers can be used. Matchers ar

4条回答
  •  借酒劲吻你
    2020-12-23 00:52

    So, by unset'ting the array index 2, you essentially remove that element in the array and decrement the array size (?).

    I made my own test..

    foo=(5 6 8)
    echo ${#foo[*]}
    unset foo
    echo ${#foo[*]}
    

    Which results in..

    3
    0
    

    So just to clarify that unset'ting the entire array will in fact remove it entirely.

提交回复
热议问题