A home-made shell for VE482 project 1.
More detailed specifications can be found here.
-
Write a working read/parse/execute loop and an
exit
command; [5] -
Handle single commands without arguments (e.g.
ls
); [5] -
Support commands with arguments (e.g.
apt-get update
orpkgin update
); [5] -
File I/O redirection: [5+5+5+2]
- Output redirection by overwriting a file (e.g.
echo 123 > 1.txt
); - Output redirection by appending to a file (e.g.
echo 465 >> 1.txt
); - Input redirection (e.g.
cat < 1.txt
); - Combine 4.1 and 4.2 with 4.3;
- Output redirection by overwriting a file (e.g.
-
Support for bash style redirection syntax (e.g.
cat < 1.txt 2.txt > 3.txt 4.txt
); [8] -
Pipes: [5+5+5+10]
- Basic pipe support (e.g.
echo 123 | grep 1
); - Run all ‘stages’ of piped process in parallel. (e.g.
yes ve482 | grep 482
); - Extend 6.2 to support requirements 4. and 5. (e.g.
cat < 1.txt 2.txt | grep 1 > 3.txt
); - Extend 6.3 to support arbitrarily deep “cascade pipes” (e.g.
echo 123 | grep 1 | grep 1 | grep 1
)
- Basic pipe support (e.g.
Note: the sub-processes must be reaped in order to be awarded the marks.
-
Support CTRL-D (similar to bash, when there is no/an unfinished command); [5]
-
Internal commands: [5+5+5]
- Implement
pwd
as a built-in command; - Allow changing working directory using
cd
; - Allow
pwd
to be piped or redirected as specified in requirement 4.;
- Implement
-
Support CTRL-C: [5+3+2+10]
- Properly handle CTRL-C in the case of requirement 4.;
- Extend 9.1 to support subtasks 6.1 to 6.3;
- Extend 9.2 to support requirement 7., especially on an incomplete input;
- Extend 9.3 to support requirement 6.;
-
Support quotes: [5+2+3+5]
- Handle single and double quotes (e.g.
echo "de'f' ghi" '123"a"bc' a b c
); - Extend 10.1 to support requirement 4. and subtasks 6.1 to 6.3;
- Extend 10.2 in the case of incomplete quotes (e.g. Input
echo "de
, hit enter and inputcd"
); - Extend 10.3 to support requirements 4. and 6., together with subtask 9.3;
- Handle single and double quotes (e.g.
-
Wait for the command to be completed when encountering >, <, or |: [3+2]
- Support requirements 3. and 4. together with subtasks 6.1 to 6.3;
- Extend 11.1 to support requirement 10.;
-
Handle errors for all supported features. [10] Note: a list of test cases will be published at a later stage. Marks will be awarded based on the number of cases that are correctly handled, i.e. if only if:
-
A precise error message is displayed (e.g. simply saying “error happened!” is not enough);
-
The program continues executing normally after the error is identified and handled;
-
-
A command ending with an & should be run in background. [10]
- For any background job, the shell should print out the command line, prepended with the job ID and the process ID (e.g. if the two lines
/bin/ls &
and/bin/ls | cat &
are input the output could be the two lines [1](32757) /bin/ls &
and [2](32758) (32759) /bin/ls | cat &
); - Implement the command jobs which prints a list of background tasks together with their running states (e.g. in the previous case output the two lines [1]
done /bin/ls &
and [2]running /bin/ls | cat &
);
- For any background job, the shell should print out the command line, prepended with the job ID and the process ID (e.g. if the two lines
Testcases can be found here which can be driven by the driver here. Credit to @tc-imba.
- Currently I can't figure out why the pipe file close of the subprocess will affect the pipe file close of the main processs.