rsh (rishav's shell) is a basic shell developed as part of the CSE-1 course (Monsoon 2019) at IIIT Hyderabad.
Notable features include piping, redirection and proper job control with foreground and background job support. Also present is history recall and tab completion for filenames.
A variety of builtins have also been implemented (see src/builtin.c
).
rsh uses the meson build system. To install, either apt install meson
or brew install meson
.
We also need the readline library. Either brew install readline
or apt install libreadline-dev
.
Then:
meson build
ninja -C build
The executable can be found at build/rsh
.
- semi-colon delimited list of jobs:
cd /; pwd; ls
- i/o redirection:
sort < in.txt > out.txt
- piping:
cat in.txt | sort | wc -l > out.txt
- start jobs in the background:
sleep 500 &
- job suspension with CTRL-Z, along with job control using
fg
andbg
- view job list:
jobs
- history recall and file-name completion
cronjob -c command -p cycle -t duration
: runcommand
everycycle
seconds forduration
seconds asynchronouslysetenv
andunsetenv
pinfo
: show process infokjob
: send signal to some arbitrary PIDoverkill
: kill all background jobs
builtin.c
: matches the input against the list of builtins; currentlycd
,pwd
,echo
,ls
,pinfo
,nightswatch
,dirty
,interrupts
,history
,quit
,jobs
,setenv
,unsetenv
,fg
,bg
,kjob
,overkill
,cronjob
.cronjob.c
: implements the cronjob builtinenv.c
: implements thesetenv
andunsetenv
builtinshistory.c
: responsible for loading the history list from disk, maintaining it in memory, and persisting to file on exitls.c
: implements thels
builtin. The-l
and-a
options are implementednightswatch.c
: implements thenightswatch
builtin; supports thedirty
andinterrupts
sub-commandspinfo.c
: implements thepinfo
builtin to fetch process information. Not supported on macOS due to lack of a procfsexternal.c
: runs external commands (non-builtins); responsible for putting newly created processes into their own groups and handling terminal controlinterpret.c
: checks if the input matches a builtin, otherwise delegates to the external handlermain.c
: runs the main REPL loop. The main shell state data structure is also defined inmain.h
. Also responsible for initializing the shell; handlingSIGCHLD
, and saving the existing term attributes for restoring laterparse.c
: tokenizes and parses the input line. Supports semicolon delimited commands, optionally ampersand terminated to indicate a background jobprompt.c
: generates the promptutil.c
: has utility functions for operating on the job table, etc.kill.c
: implements thekjob
andoverkill
builtins
- Input of the form
foo>out.txt
orfoo> out.txt
is not parsed correctly.
See LICENSE.txt