Skip to content

vancenceho/unix-cseshell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CSEShell

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.

Features

Resource Usage Feedback

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.

Resource Usage Feedback Example

Keyboard Shortcuts

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.

Inclusive Error Messaging

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 help and usage pages that introduce the shell to new users.

These features help users understand how to use CSEShell better, faster; providing a seamless user experience.

Inclusive Error Messaging Example

Built-In Commands

The following commands are supported as built-in functions:

  • cd
  • clear
  • env
  • exit
  • help
  • setenv
  • unsetenv
  • usage

cd

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.

cd Example

clear

The clear command clears (resets) the shell terminal, as per the normal Unix clear command.

env

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)

exit

The exit command terminates CSEShell.

exit Example

help

The help command displays the general overview of supported commands for CSEShell, including both supported built-in and system commands.

help Example

setenv

The setenv command sets or modifies an environment variable for the CSEShell shell session (not persistent).

unsetenv

The unsetenv command removes an environment variable for the CSEShell shell session (not persistent).

usage

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.

usage Example

.rc File

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 .cseshellrc

Modifying PATH Environment Variable

Get 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/bin

Running System Programs and Builtin Functions

The 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
sys

where cal and sys are system programs.

Results in

.rc file example

System Commands

The following commands are supported as system programs in our shell.

  • sys
  • dspawn
  • dcheck
  • backup

sys

The sys command prints out basic information about your operating system as follow:

sys Example

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 -os
  • sys -user
  • sys -hardware

An example is shown below:

sys Options Example

dspawn

The dspawn command spawns a daemon process and terminates to show the next prompt immediately, the observed output is shown below:

dspawn Example

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:

dspawn.log Example

dcheck

The dcheck command simply checks how many live daemons (spawned from dspawn).

dcheck Example

backup

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:

backup_dir Example

It also works on if BACKUP_DIR is set to a file instead of a directory:

backup_file Example

We can then view the outputs of the example as follows:

backup_output Example

Directory Structure

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.c and builtin.h - Source and header files for the built-in commands.
    • output.c and output.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.

Installation

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:

make

This will compile the source code and place the executable files in the appropriate directories.

After building, you can start the shell by running:

./cseshell

From 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 clean

Acknowledgements

This project is an undertaking of the 50.005 Computer System Engineering module under the Singapore University of Technology and Design.

Review Assignment Due Date

About

A simple custom shell for Unix-based systems ⌨️

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published