I made a simplistic shell in one of my university CS classes as a lab. Although we only were required to support a few commands, I started to wonder how a fully functional shell supports the parsing of hundreds of different commands. In my simplistic shell I just had six or so if statements of the format,
if(command == 'history')
show the last ten commands
if(command == 'exit')
close the shell
etc...
However if you had a shell with hundreds of possible commands it seems endless sequence of if-statements would be somewhat clumsy especially whenever you wanted to add new commands to your shell. Is there any data structure that can be used for command parsing? How would you go about adding a new command to a shell?
Aucun commentaire:
Enregistrer un commentaire