Write a Shell in C/C++.
It’s easy to view yourself as “not a real programmer.” There are programs out there that everyone uses, and it’s easy to put their developers on a pedestal. Although developing large software projects isn’t easy, many times the basic idea of that software is quite simple. Implementing it yourself is a fun way to show that you have what it takes to be a real programmer.
A shell does three main things in its lifetime.
(1) Initialize
(2) Interpret
(3) Terminate
The shell should support pipe (|), service (&), and file redirection (<, >, >>).
The following commands (with their traditional objective)should be implemented:
cd:
cd [directory]
‘~’, ..
, ‘/’ are valid (along with alphanumeric characters) and stand for traditional meaning.
pwd:
pwd [OPTION]
ls:
ls [OPTION]... [FILE]...
Option: -l, -r, -s, --file-type (match file extension).
Exit:
exit
Quite the shell (Terminate).
Find:
find path -name filename
for example,
find . -name a.txt
find . -name *.txt
File Redirection(>,>>,<):
ls -l > a.txt
ls -l >> a.txt
ls -l < b.txt (in b.txt we have filename, for example ./shell)
find . -name b.txt > a.txt
Service(&):
find . -name a.txt &
History:
history
Pipeline
ls | pwd
Interrupt(Ctrl+C)
C++
Weili, Shi
Sixiang, Zhang
run the following command.
./shell