Implement shell expansion

I am trying to create a custom wrapper as an exercise and would like to implement a wildcard extension. How exactly do shells like bash perform extension? I mean, are all the steps involved?

As I understand it, the shell looks for the file names in the current directory and replaces the argument containing "*" with the file names that must match. It's right? What other wildcard extensions should contain a shell other than '*'

+3
source share
3 answers

Bourne shell [original sh] supports extension *, ?and [range]. bash also supports**

0
source

. , :

  • , , .
  • FSM, FSM - , .
  • .
  • Determining whether a candidate matches a given wildcard expression by performing some sort of matching algorithm using a prebuilt RE or FSM.
  • Gathering the submitted candidates together in the list, replacing the wildcard with the assembled list.

For the full range of different characters, see the documentation for specific shell implementations (for example, for bash , zsh , etc.). Most of these materials are mapped directly into one or more regular expression functions, like a mechanism.

0
source

Source: https://habr.com/ru/post/1790585/


All Articles