Using unset vs. setting a variable to empty

前端 未结 4 1097
一生所求
一生所求 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:41

    As has been said, using unset is different with arrays as well

    $ foo=(4 5 6)
    
    $ foo[2]=
    
    $ echo ${#foo[*]}
    3
    
    $ unset foo[2]
    
    $ echo ${#foo[*]}
    2
    

提交回复
热议问题