I’m implementing a linux shell for my weekend assignment and I am having some problems implementing wilcard matching as a feature in shell. As we all know, shells are a complete language by themselves, e.g. bash, ksh, etc. I don’t need to implement the complete features like control structures, jobs etc. But how to implement the *?
A quick analysis gives you the following result:
echo *
lists all the files in the current directory. Is this the only logical manifestation of the shell? I mean, not considering the language-specific features of bash, is this what a shell does, internally? Replace a * with all the files in the current directory matching the pattern?
Also I have heard about Perl Compatible Regular Expression , but it seems to complex to use a third party library.
Any suggestions, links, etc.? I will try to look at the source code as well, for bash.
Yes, that’s what shell does. It will replace
'*'characters by all files and folder names incwd. It is in fact very basic regular expressions supporting only'?'and'*'and matching with file and folder names incwd.Remark that backslashed
\*and'*'enclosed between simple or double quotes'or"are not replaced (backslash and quotes are removed before passing to the command executed).