Skip to main content
removed redundant `case` word; reformatted to help readability, removed extra formatting symbols
Source Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 266

Look at the following:

$ echo .[].aliases[] .. $ echo .[].foo[] .. $ echo .[].[] .. $ echo .[].xyz[] .. $ echo .xyz[].xyz[] .xyz[].xyz[] $ echo .xyz[].[] .xyz[].[] 

So apparentlyApparently this seems to be globbing something, but I don’t understand how the result comes together. From my understanding [] is an empty character class. It would be intuitive if it matched only the empty string (in this case, I’d expect bash to reproduce in its entirety since nothing matches it in this directory, but also match things like ..aliases (in the first example)), or nothing at all (in this case case, I’d expect bash to reproduce the string in total, too).

  • it matched only the empty string; in this case, I’d expect bash to reproduce in its entirety since nothing matches it in this directory, but also match things like ..aliases (in the first example),
  • or nothing at all; in this case, I’d expect bash to reproduce the string in total, too.

This is with GNU bash, version 4.4.23(1)-release.

Look at the following:

$ echo .[].aliases[] .. $ echo .[].foo[] .. $ echo .[].[] .. $ echo .[].xyz[] .. $ echo .xyz[].xyz[] .xyz[].xyz[] $ echo .xyz[].[] .xyz[].[] 

So apparently this seems to be globbing something, but I don’t understand how the result comes together. From my understanding [] is an empty character class. It would be intuitive if it matched only the empty string (in this case, I’d expect bash to reproduce in its entirety since nothing matches it in this directory, but also match things like ..aliases (in the first example)), or nothing at all (in this case case, I’d expect bash to reproduce the string in total, too).

This is with GNU bash, version 4.4.23(1)-release.

Look at the following:

$ echo .[].aliases[] .. $ echo .[].foo[] .. $ echo .[].[] .. $ echo .[].xyz[] .. $ echo .xyz[].xyz[] .xyz[].xyz[] $ echo .xyz[].[] .xyz[].[] 

Apparently this seems to be globbing something, but I don’t understand how the result comes together. From my understanding [] is an empty character class. It would be intuitive if

  • it matched only the empty string; in this case, I’d expect bash to reproduce in its entirety since nothing matches it in this directory, but also match things like ..aliases (in the first example),
  • or nothing at all; in this case, I’d expect bash to reproduce the string in total, too.

This is with GNU bash, version 4.4.23(1)-release.

edited tags
Link
Gilles 'SO- stop being evil'
  • 865.9k
  • 205
  • 1.8k
  • 2.3k
Tweeted twitter.com/StackUnix/status/1028340616005079040
Source Link
Jonas Schäfer
  • 1.8k
  • 2
  • 15
  • 25

What does `.[].foo[]` do in bash? Why does it match `..`?

Look at the following:

$ echo .[].aliases[] .. $ echo .[].foo[] .. $ echo .[].[] .. $ echo .[].xyz[] .. $ echo .xyz[].xyz[] .xyz[].xyz[] $ echo .xyz[].[] .xyz[].[] 

So apparently this seems to be globbing something, but I don’t understand how the result comes together. From my understanding [] is an empty character class. It would be intuitive if it matched only the empty string (in this case, I’d expect bash to reproduce in its entirety since nothing matches it in this directory, but also match things like ..aliases (in the first example)), or nothing at all (in this case case, I’d expect bash to reproduce the string in total, too).

This is with GNU bash, version 4.4.23(1)-release.