Is there an easy way to set nullglob for one glob

前端 未结 5 1107
谎友^
谎友^ 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:25

    This is just a tiny bit better than your original suggestion:

    local nullglob=$(shopt -p nullglob) ; shopt -s nullglob
    

    ... do whatever you want ...

    $nullglob ; unset nullglob
    

提交回复
热议问题