A very basic version of shell implemented in C.
- Run the command
make
. - Run
./Jarvish
to get a banner with "J.A.R.V.I.SH." written followed by a prompt of the form<username@system_name:path>
highlighted in cyan. The directory from where the shell is executed is the home(~) directory for the shell - Run any command in the shell. It can entail as many number of tabs and spaces, the shell accounts for those.
- In order to exit, run
quit
orexit
orctrl+C
.
These commands have been defined by me and are contained within the shell itself. Jarvish shows an error message if any invalid command is entered.
-
echo [arguments]
- Displays whatever is specified in [arguments].
- Implemented in echo.c
-
cd [directory]
- Changes directory to the directory specified, throws an error if the directory does not exist or if there are incorrect number of arguments.
- Variations such as
cd, cd . , cd .., cd ~
also work. cd -
prints the previous working directory and switches to the previous working directory.- Implemented in cd.c
-
ls [-l -a] [directory]
- Lists all the files and directories in the specified directory in alphabetical order.
- Variations such as
ls, ls . , ls .., ls ~
also work. - Also handles multiple directories as arguments. eg.
ls -l dir1 dir2 dir3
. - Mimics behaviour of bash by just printing filename if
ls
is tried on anything other than a directory. - Implemented in ls.c
-
pwd
- Displays the name of the working directory.
- Implemented in command.c
-
pinfo [PID]
- Prints numerous details about the process such as its status, memory, and executable path.
- Just
pinfo
with no arguments gives details of the shell. - Implemented in pinfo.c
-
setenv var [value]
- Sets value of the environment variable
var
to [value]. If value is omitted, the variable's value is set to an empty string. - Implemented in command.c
- Sets value of the environment variable
-
unsetenv var
- Destroys the environment variable
var
, if it exists. - Implemented in command.c
- Destroys the environment variable
-
jobs
- Prints a list of all existing background processes spawned by the shell in order of their creation times.
- Prints job number, process ID and their state, which can either be "running" or "stopped".
- Implemented in jobs.c
-
kjob <job number> <signal number>
- Sends the signal corresponding to 'signal number' to the job number specified.
- Throws error if
job number
is invalid orsignal number
is invalid. - Implemented in kjob.c
-
fg <jobNumber>
- Brings a running or a stopped background job corresponding to
job number
to foreground. - Throws error if
job number
is invalid - Implemented in fg.c
- Brings a running or a stopped background job corresponding to
-
bg <jobNumber>
- Changes a stopped background job to a running background job.
- Throws error if
job number
is invalid - Implemented in bg.c
-
overkill
- Kills all background process at once.
- Implemented in overkill.c
-
quit
orexit
orctrl+D
- Exits the shell, closing (sending SIGKILL to) all background processes and updates history.txt file.
All other valid commands are treated as system commands like emacs, vim etc. This is implemented in executeSys.c]
- Command followed by '&' symbol is run in the background. Eg.
emacs &
. - Upon termination of a background process, the shell prints in red its PID, name and if it exits abnormally, the exit status.
- When a background process is run, it prints number of background processes running currently and the pid of the last background process.
- Implemented in executeSys.c
-
history [num]
- Lists the last [num] commands. If no arguments are specified, it displays the last 10 commands.
- Retains upto 20 commands even upon shell exit - uses history.txt to store these commands.
- Implemented in history.c
-
nightswatch -n [seconds] [interrupt/newborn]
interrupt
argument prints the number of times CPU has been interrupted by keyboard.newborn
argument prints pid of the most recently created process.- Executes every [seconds] number of seconds as specified by user.
- To exit press
q
and hitenter
. - Error handling done for incorrect arguments.
-
Input-Output Redirection & Piping
- Handles
<
,>
,>>
, and|
operators appropriately, wherever they are in the command
- Handles
-
ctrl+Z
- Pushes any currently running foreground job into the background, and changes its state from running to stopped
-
ctrl+C
- Interrupt any currently running foreground job, by sending it SIGINT signal
- If there is no foreground job, then the signal does not have any effect.
-
Exit Codes
- Exit codes indicate whether a process exited normally, or encountered an error.
-
:')
is displayed alongside the next prompt if the previous command exited successfully and :'(
is displayed if it encountered an error - For a pipeline or a semicolon separated list of commands, the exit status corresponds to that of the last command in the pipeline/list.
-
Command chaining with Logical AND and OR
- The logical AND and OR operators can be used to chain commands, such that the exit code of the entire chain is the logical AND or OR (respectively) of the individual exit codes
@
is used to denoteAND
and$
forOR
- Length of input should be less than 2000 characters in total.
- No more than 20 chained commands should be there.
- No more than 100 semi-colon separated commands should be there.