Implemented a shell program with low-level Unix/POSIX system calls in November 2017 at Stony Brook University.
NOTE: If you are a student in such a class, you should not copy (or copy then modify) this code without permission.
wyjeong-shell which supports command-lines with low-level Unix/POSIX system calls related to processes, files, and interprocess communication (pipes and redirection) has implemented.
Supports the following builtins.
help: Print a list of all builtins and their basic usage in a single column.
exit: Exits the shell by using the
cd: Changes the current working directory of the shell by using the
cd -should change the working directory to the last directory the user was in.
cdwith no arguments should go to the user’s home directory which is stored in the
cd ..should be handled correctly.
..are special directories that appear in every directory of a Unix system. They correspond to the current directory and previous directory of the current working directory.
pwd: Prints the absolute path of the current working directory. This can be obtained by using the
wyjeong_shell supports any executables, such as
Supports redirection syntax that uses three special characters:
< for input redirection,
> for output redirection, and
| for piping.
prog1 [ARGS] > output.txt
prog1 [ARGS] < input.txt
prog1 [ARGS] < input.txt > output.txt
prog1 [ARGS] > output.txt < input.txt
prog1 [ARGS] | prog2 [ARGS] | ... | progN [ARGS]
prog1 [ARGS] < input.txt | prog2 [ARGS] | ... | progN [ARGS]
prog1 [ARGS] | prog2 [ARGS] | ... | progN [ARGS] > output.txt
Supports a subset of the Bash’s job control tools as follows:
jobs: This command prints a list of the processes stopped by
fg %JID: This command resumes the process identified by the provided
kill %JID: This command forces the process identified by the provided
JIDto terminate using a
kill PID: If no percent sign is provided, assume the number is a PID, and send
SIGKILLto that pid.
Ctrl-C: This keybinding sends a
SIGINTsignal to the program currently running in the foreground.
Ctrl-Z: This keybinding sends a
SIGTSTPsignal to the program currently running in the foreground.
wyjeong_shell also supports Job Control + Piped Processes.
Supports background processing:
&: If a command ends with a this symbol, then the shell does not wait for the program to terminate before returning a prompt to the user. The process should still be assigned a unique job ID and added to your job list.
Supports both interactive commands as well as reading commands from a file via IO redirection. Both scenarios are similar, however, when reading commands from a file, the shell should not print its prompt.
$ wyjeong_shell < testcmds.sf
$ cat testcmds.sf | wyjeong_shell
In this scenario,
testcmds.sf would be a series of commands separated by new line characters, like so:
help ls cd / pwd ls -al home cd - cat < testcmds.sf ping google.com -c 2 | tr '[:lower:]' '[:upper:]' exit
Source code will be public on my github accout soon.