CSEShell is a simple, custom shell for Unix-based systems, designed to provide an interface for executing system programs. This project includes a custom shell implementation, a set of system programs, and some test files.
CSEShell will display system statistics to the user on each command call. These statistics include:
- User and system CPU time usage of each command call.
- Resident set size (RSS) of the CSEShell program in main memory.
These statistics serve to remind the user of his/her energy usage while running CSEShell and promote sustainable use of the program.
CSEShell supports auto-completion and loading of previous commands via keyboard shortcuts (Tab and ^ respectively).
Alongside additional features such as quotation-enclosed argument parsing, these features serve to make the user experience as intuitive and forgiving as possible for all users.
CSEShell supports first-time and veteran users alike with its friendly messaging interface, which includes:
- Colour-coded, terminology-friendly, and verbose error and warning messages.
- Useful
helpandusagepages that introduce the shell to new users.
These features help users understand how to use CSEShell better, faster; providing a seamless user experience.
The following commands are supported as built-in functions:
- cd
- clear
- env
- exit
- help
- setenv
- unsetenv
- usage
The cd command changes the current working directory of CSEShell to the specified directory.
It uses the same syntax (e.g. "..", "~", etc.) as a normal Unix cd command.
The clear command clears (resets) the shell terminal, as per the normal Unix clear command.
The env command lists all system environment variables.
This includes variables set within CSEShell and those already set by the host system.
(Image redacted for privacy and security)
The exit command terminates CSEShell.
The help command displays the general overview of supported commands for CSEShell, including both supported built-in and system commands.
The setenv command sets or modifies an environment variable for the CSEShell shell session (not persistent).
The unsetenv command removes an environment variable for the CSEShell shell session (not persistent).
The usage command provides a brief description of how to use a given built-in command.
Each description comes with command-line syntax, relevant examples, and other relevant built-in commands to check out.
The shell reads and runs commands from .cseshellrc whenever it is executed.
You can make your own using an example .rc file (.cseshellrc.example) by running:
cd project_directory
cp .cseshellrc.example .cseshellrcGet your project path with the pwd system command and append "/bin" to it. Your resulting PATH should look like:
PATH=/Users/natalie_agus/Desktop/pa1-2024/bin:/usr/binThe rest of the file can be used to call other system programs or builtin functions. Just make sure each command is on its own line like below:
In .cseshellrc
PATH=/Users/natalie_agus/Desktop/pa1-2024/bin:/usr/bin
clear
cal
syswhere cal and sys are system programs.
Results in
The following commands are supported as system programs in our shell.
- sys
- dspawn
- dcheck
- backup
The sys command prints out basic information about your operating system as follow:
Additionally, instead of the overall system information, I included an option to display useful information such as OS, user, and hardware specifically. The commands are as followed:
sys -ossys -usersys -hardware
An example is shown below:
The dspawn command spawns a daemon process and terminates to show the next prompt immediately, the observed output is shown below:
After the daemon is spawn, it would be writing to a file at PROJECT[DIR]/dspawn.log to log its behaviour as we can see below:
The dcheck command simply checks how many live daemons (spawned from dspawn).
Lastly, the backup command would automatically zip any file or folder defined in BACKUP_DIR using setenv. The filename is automatically set to backup-YYYYMMDDHHMMSS.zip and will be located in the[PROJECT_DIR]/archive/.
Here is an example of how backup works once BACKUP_DIR is set:
It also works on if BACKUP_DIR is set to a file instead of a directory:
We can then view the outputs of the example as follows:
The project is organized as follows:
files/- Contains various test files used with the shell and system programs.combined.txt,file1.txt,file2.txt, ... - Test text files.notes.pdf- A PDF file for testing.ss.png- An image file.
source/- Source code for the shell and system programs.shell.c- Source file for the shell.builtin.candbuiltin.h- Source and header files for the built-in commands.output.candoutput.h- Source and header files for functions dealing with terminal output.system_programs/- Source code and header for the system programs.
makefile- Makefile for building the CSEShell and system programs.
To build the CSEShell and system programs, first create a local copy of .cseshellrc by duplicating .cseshellrc.example and replacing PATH_TO_PROJECT_BIN_FOLDER with the appropriate path to the bin folder of the project.
Next, run the following command in the root directory:
makeThis will compile the source code and place the executable files in the appropriate directories.
After building, you can start the shell by running:
./cseshellFrom there, you can execute built-in commands and any of the included system programs (e.g., find, ld, ldr).
The Makefile contains rules for compiling the shell and system programs. You can clean the build by running:
make cleanThis project is an undertaking of the 50.005 Computer System Engineering module under the Singapore University of Technology and Design.














