Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

10
  • There's another usability issue: nullglob appears to break tab-completion (pressing the tab key does nothing when it's enabled). Commented Jul 5, 2016 at 16:01
  • 1
    It's possible to use nullglob on a per glob basis with bash - although the syntax is not as elegant as zsh files=$(shopt -s nullglob;echo *.txt) Commented Sep 21, 2017 at 21:33
  • 7
    @JonNalley, that stores the concatenation (with space) of the file names (with possible transformation with xpg_echo) into a scalar variables. You'd need something like readarray -td '' files < <(shopt -s nullglob; printf '%s\0' *.txt) with bash 4.4 or above or (shopt -s nullglob; printf '%s\0' *.txt) | xargs -r0 cmd with GNU xargs for that to be usable at all with arbitrary file names. Or, still with bash4.4, use a helper function that uses local - (copied from ash 25 years later) for a local scope for options. Commented Sep 22, 2017 at 7:31
  • 1
    @midnite I do explain that set -o nullglob; ls -- *.txt lists the current working directory instead of txt files or grep foo ./*.txt greps stdin instead of txt files which is worse than letting ls/grep complain about those non-existent files. Commented Jan 10, 2024 at 9:48
  • 1
    Regarding the comment above, "use a helper function that uses local - for a local scope for options": unfortunately, this only works for the options that Bash sets with set, not the ones that can only be controlled using shopt. Commented Mar 27 at 16:52