Is there an easy way to set nullglob for one glob

前端 未结 5 1101
谎友^
谎友^ 2021-02-03 23:22

In bash, if you do this:

mkdir /tmp/empty
array=(/tmp/empty/*)

you find that array now has one element, \"/tmp/empty/*\"

5条回答
  •  广开言路
    2021-02-04 00:12

    Unset it when done:

    shopt -u nullglob
    

    And properly (i.e. storing the previous state):

    shopt -u | grep -q nullglob && changed=true && shopt -s nullglob
    ... do whatever you want ...
    [ $changed ] && shopt -u nullglob; unset changed
    

提交回复
热议问题