Hacker Timesnew | past | comments | ask | show | jobs | submitlogin

If we're talking about bash, I think it's a mistake to refer to any of this as "glob expansion", a term which doesn't appear in the bash man page. Rather, it differentiates between multiple types of expansion and the order in which they take place. Quote:

The order of expansions is: brace expansion, tilde expansion, parameter, variable and arithmetic expansion and command substitution (done in a left-to-right fashion), word splitting, and pathname expansion.

On systems that can support it, there is an additional expansion available: process substitution.

Furthermore, expansion absolutely does work on the first word and it's not obvious to me why someone might think it doesn't. The simplest example is probably tilde expansion, i.e. the ability execute ~/bin/foo or ~someone/bin/bar. But the other types work too, e.g. brace expansion:

    $ ls l1
    ls: l1: No such file or directory
    $ l{s,1}
    ls: l1: No such file or directory
    $ touch l1
    $ l{s,1}
    l1
Command substitution:

    $ $(echo l)s -l l1
    -rw-r--r--  1 user  wheel  0 10 Dec 14:12 l1
Arithmetic expansion:

    $ perl$((4+1)).$((36/2)) -E 'say "foo"'
    foo
Even pathname expansion - here, `fi*` expands to `find` from $CWD, which is then found in $PATH and executed:

    $ ls -l
    $ touch find foo bar quux
    $ fi* . -name f\*
    ./foo
    ./find
And so on.*


> I think it's a mistake to refer to any of this as "glob expansion"

Since we are being pedantic regarding the terms, while I can't really find "glob expansion" in the Bash manual either, it documents a bunch of "glob" settings: "noglob", "GLOBIGNORE", "dotglob", "extglob"...[1]

FWIW, I expected to find these in the Bash info page on Ubuntu, but curiously, "info bash" does not show up the info page (just the fallback manpage) — "info find" does work. Whatever happened to (tex)info pages?

[1]https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash....


The * character is addressed in pattern matching rather than parameter expansion.

From the bash manpage (version 5.0):

The special pattern characters have the following meanings:

* Matches any string, including the null string. When the globstar shell option is enabled, and * is used in a pathname expansion context, two adjacent *s used as a single pattern will match all files and zero or more directories and subdirectories. If followed by a /, two adjacent *s will match only directories and subdirectories.

The GNU bash manual describes the '-f' option as "Disable filename expansion (globbing)."

"Globbing" is how * expansion is generally referenced in other documents, if not often within the bash manpage or info pages themselves.


> ...expansion absolutely does work on the first word

As was already pointed out, you are right. It does not work to match executables in the $PATH, which is what I was, for some reason, trying to communicate badly.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: