Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

implement wildcard expansion in a shell

I am trying to create custom shell as an exercise and wanted to implement wildcard expansion. How exactly do shells like bash perform the expansion? I mean what all steps are involved?

As I understand, the shell looks for file names in the current directory and replaces the argument which contains the '*' with the filenames which should match. Is this correct? What other wildcard expansions should a shell do other than a '*'

like image 314
randomThought Avatar asked Dec 08 '25 15:12

randomThought


1 Answers

The POSIX specification describes the word expansions that POSIX-compliant shells should support. You can use the glob or wordexp POSIX functions to perform these expansions (glob supports only a small subset of the expansions that wordexp supports).

like image 143
Dan Moulding Avatar answered Dec 12 '25 15:12

Dan Moulding



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!