Hey, this is a shell I created!
- Clone the directory
- run
make
inside the directory - Profit!
MAXLEN = 1024
, which is the maximum length of strings, maximum length of arguments etc
-
Use
;
to use multiple commands in the same line! -
How does it work? sash uses a tokenizer to split the command line arguments based on
;
-
One can also use
|
to pipe commands likels -al | wc
, where the output ofls -al
becomes input ofwc
. This was done using an iterative function and C'spipe()
command -
You can also use
>
,<
or>>
for redirecting input manually, and this can also be used with piping.
- Change the directory to place mentioned by using
cd
- `~ . .. -~ can be used just as you would in a normal shell
- A very simple and effecient implementation where sash gets the relative path from current dir to required, and then changes directory.
- Get path to the current working directory by using
pwd
- Simply gets the absolute path of current working directory, then converts it into relative based on
home
- Print everything which follows the command
echo
- Print the information for a given Process ID using
pid
- Gives information about:
- Proccess ID
- Process Status
- Virtual Memory
- Executable Path
- Reads extra information from
proc
files and displays it accordingly.
- Prints all the background processes which arent terminated yet
jobs
. -r
flag only prints running jobs, and-s
flag only prints stopped jobs- To implement this, sash stores a array of structs with all the background jobs in it. It also works in conjuction with
CTRL+Z
.
- Sends a signal given index (of process in job list) and signal to send.
- Sash uses
kill
to implement this function
- Brings a stopped background process back to life!! (still in background tho)
- A signal is sent to the process to achieve this
- A very simple command
replay -command echo hi -interval 3 -period 6
where commandecho hi
is executed every3 seconds
till6 second
pass. - This was done using C's
<time.h>
module andsleep()
function
- Basing signal handling is implemented to keep sash as close to normal bash, where
CTRL+
terminates a foreground process,CTRL+Z
stopps a foreground process and takes it to background andCTRL+D
exits the shell
- The main loop is within
sash.c
, which also intialises constants likehome
and sets upsignal
- Then command goes to
command.c
which parses the input string, and redirects it accordingly - In each loop, we run
info.c
to print the prompt cd.c
contains code related to cdls.c
contains code related to lspinfo.c
contains code related to pinfopwd.c
contains code related to pwdprint.c
contains code related to echosignal.c
handles reaping the background child processes, also does signal handlingground.c
contains code related tobg
jobs.c
prints a list of jobs and contains code for itpipe.c
is the first step of command parsing, which then goes toredirect.c
redirect.c
is the second part of command parsing which then goes tocommand.c
replay.c
is used to handle the commandreplay
. It callspipe.c
to execute the said commandsig.c
is code related tosig
functionutilities.c
contains some functions which are used everywhereheader.h
contains some headers and function definitions