- main.c
- This file contains the main shell loop.
It reads user input and calls the necessary functions to parse the input and figure out the command to be executed. - input_handling.c
- This file contains the code for parsing the input. It parses the input into different commands and parses the commands into different arguments.
- defs.h
- This file contains the declarations of the functions used in the shell.
- display.c
- This file contains definitions for the functions related to display the shell prompt.
- handlers.c
- This file contains the definitons for the functions dealing with signal handling.
- junction.c
- This file contains code to figure out the command to be executed and after some preprocessing (if needed) like redirection setup, call the corresponding function.
- Rest
- Rest of the files contain code for implementation of the command\feature implied by the file name.
- clear
-
- Function:
- Clears the terminal screen
- Syntax:
-
-
clear
-
Ctrl-L
-
- quit
-
- Function:
- Exits the shell
- Syntax:
-
-
quit
-
exit
-
q
-
- ls
-
- Function:
- Basic implementation of ls. Supprts 'a' and 'l' flags.
- Syntax:
-
ls [-al] [dir\file path]
- Note:
-
- If path is not given, path will be set to '.'.
- Paths with spaces also supported. (Enclose in "").
- cd
-
- Function:
- Basic implementation of cd.
- Syntax:
-
cd [directory]
- Note:
-
- If directory is omitted, '~' will be treated as directory.
- echo
-
- Function:
- Basic implementation of echo.
- Syntax:
-
echo < phrase >
- Note:
-
- Regex not supported.
- pwd
-
- Function:
- Basic implementation of pwd.
- Syntax:
-
pwd
- pinfo
-
- Function:
- Gives information (pid, status, executable path, etc) about a given process.
- Syntax:
-
pinfo [pid]
- Note:
-
- If pid is omitted, pid of shell is used.
- nightswatch
-
- Function:
- Perodically displays the number of times the cpu has been interrupted by the keyboard (interrupt) or the size of part of memory which is dirty (dirty).
- Syntax:
-
nightswatch -n < seconds > < mode >
- Options:
-
- seconds: Time interval for repitition.
- mode: 'interrupt' or 'dirty'.
- history
-
- Function:
- Displays the past commands.
- Syntax:
-
history [number]
- Options:
-
- number: Number of commands to display. [0-20]
- Note:
-
- If number is omitted, 10 commands are displayed.
- jobs
-
- Function:
- Lists all the background jobs currently running.
- Syntax:
-
jobs
- Note:
- kjob
-
- Function:
- Sends a given signal to the given job.
- Syntax:
-
kjob < job > < signal >
- Options:
-
- job: job number
- signal: signal number to be sent
- fg
-
- Function:
- Change the status of given job from background to foreground.
- Syntax:
-
fg [job]
- Options:
-
- job: job number
- Note:
-
- If job is omitted, the latest job is considered.
- bg
-
- Function:
- Change the status of a job from stopped in background to running in background.
- Syntax:
-
bg [job]
- Options:
-
- job: job number
- Note:
-
- If job is omitted, latest job is considered.
- overkill
-
- Function:
- Terminate all jobs running in the background.
- Syntax:
-
overkill
- getenv
-
- Function:
- Get the value of an environment variable.
- Syntax:
-
getenv < env >
- Options:
-
- env: Environment variable
- setenv
-
- Function:
- Set the value of an environment variable.
- Syntax:
-
setenv < env > < value >
- Options:
-
- env: Environment vairable.
- value: Value to set env to.
- unsetenv
-
- Function:
- Unset environment variable.
- Syntax:
-
unsetenv < env >
- Options:
-
- env: Environment variable.
- cronjob
-
- Function:
- Run a command periodically for a given amount of time.
- Syntax:
-
cronjob -c < command > -t < period > -p < total >
- Options:
-
- command: command to be run.
- period: Time (seconds) after which to run the command again.
- total: total time for which the command is to be run.
- Other
-
- Function:
- Runs all the other shell commands using execvp.
- Piping
- Redirection
- Command recall using 'UP' key
- Job control
- Supports foreground and background processes. Supports switching a proccess from background to foreground and vice versa.
- Signal Handling
- Ctrl-Z and Ctrl-C have no effect in main shell but when a command is running, Ctrl-C sends SIGSTOP to it and Ctrl-Z sends it to background.
- Clone this repository:
git clone addr
- Cd into the directory:
cd C-sh
- Compile the code:
make
- Run the shell:
./shell