A Very basic Shell.
It's the course project (option 1) for Computer System Architechture, Professor Mao, Tsinghua SEM.
- System: Linux
- Compiler: gcc
Building:
$ make
Running:
$ ./vsh.exe
- Display prompt information (current working directory) and accept a command that the user keys in and execute the command
- The command can be an executable in the
PATH
followed by its arguments - or
cd SOME_DIR
, which changes the working directory, and is the only supported built-in command
- The command can be an executable in the
- When the execution is finished, the prompt will be displayed again and wait for next command
- The interpreter can be terminated with command
bye
- Multiple commands in one line are allowed, they should be separated by
&&
- Execute the command in background when the character
*
is append to the end of one command. Note that this will prevent commands from using*
as a wildcard parameter. - The shell will not terminate from being interrupted by
Ctrl-C
Note that the cognominal .h
file is not listed here.
📦V-Shell
┣ 📂src
┃ ┣ 📂util
┃ ┃ ┣ 📜config.h
┃ ┃ ┣ 📜debug.c
┃ ┃ ┣ 📜dir.c
┃ ┃ ┣ 📜execute.c
┃ ┃ ┣ 📜input.c
┃ ┃ ┣ 📜signalHandling.c
┃ ┗ 📜vshell.c
┣ 📜.gitignore
┣ 📜Makefile
┗ 📜README.md
src/util/config.h
: Define constants, macros, messages, syntax, etc. for the whole project.src/util/debug.c
: Provide print functions for debugging.src/util/dir.c
: Manage the current working directory.src/util/execute.c
: Kernel of v-shell, execute the input commands.src/util/input.c
: Receive user input and split them.src/util/signalHandling.c
: HandlingCtrl+C
signals.src/vshell.c
: Entry point of the shell.
In the following demonstration, the lines start with \\
are comments and explanations, while others are either output in the console or the user input.
\\ Entering the v-shell
root@4683062396b4:/usr/vopaaz/v-shell# ./vsh.exe
--------
This is a very basic shell by Vopaaz (Li YiFan) in June 2019.
It's the course project for Computer System Architechture, Professor Mao.
--------
\\ Basic commands supported
/usr/vopaaz/v-shell > ls
Makefile README.md src syncDocker.bat vsh.exe
\\ Redundant space before the first valid command
/usr/vopaaz/v-shell > ls
Makefile README.md src syncDocker.bat vsh.exe
\\ Basic command and parameters
/usr/vopaaz/v-shell > ls -a
. .git .vscode README.md syncDocker.bat
.. .gitignore Makefile src vsh.exe
\\ Redundant space within the command
/usr/vopaaz/v-shell > ls -a
. .git .vscode README.md syncDocker.bat
.. .gitignore Makefile src vsh.exe
\\ Built-in cd function that changes the working directory
/usr/vopaaz/v-shell > cd ..
/usr/vopaaz > cd v-shell
\\ Use '*' to execute command in the background
/usr/vopaaz/v-shell > ls *
Command executing in the background, child process id [3012]
/usr/vopaaz/v-shell > Makefile README.md src syncDocker.bat vsh.exe
\\ Note that the shell prompts first then comes the output of 'ls'.
\\ Multiple commands in one line, separated by '&&'
/usr/vopaaz/v-shell > ls && ls && ls
Makefile README.md src syncDocker.bat vsh.exe
Makefile README.md src syncDocker.bat vsh.exe
Makefile README.md src syncDocker.bat vsh.exe
\\ Multiple commands executed in the background
/usr/vopaaz/v-shell > ls * && ls * && ls *
Command executing in the background, child process id [3016]
Command executing in the background, child process id [3017]
Command executing in the background, child process id [3018]
/usr/vopaaz/v-shell > Makefile README.md src syncDocker.bat vsh.exe
Makefile README.md src syncDocker.bat vsh.exe
Makefile README.md src syncDocker.bat vsh.exe
\\ Available to handle commands that does not exist
/usr/vopaaz/v-shell > commands-that-not-exist
Execution failed. Commands may be invalid.
\\ If multiple commands are in one line and some of them are invalid,
\\ only those valid ones before the invalid one will execute.
/usr/vopaaz/v-shell > ls && commands-that-not-exist
Makefile README.md src syncDocker.bat vsh.exe
Execution failed. Commands may be invalid.
/usr/vopaaz/v-shell > ls && commands-that-not-exist && ls
Makefile README.md src syncDocker.bat vsh.exe
Execution failed. Commands may be invalid.
\\ Able to handle when no command follows the '&&' syntax
/usr/vopaaz/v-shell > ls &&
Makefile README.md src syncDocker.bat vsh.exe
\\ The shell is prevented from being interrupted by 'Ctrl+C'
/usr/vopaaz/v-shell > ^C
Ctrl+C detected, but the shell does not terminate according to the instruction.
To exit the shell, either use 'bye' or press 'Ctrl+Z'
\\ The shell can be terminated using bye
/usr/vopaaz/v-shell > bye
root@4683062396b4:/usr/vopaaz#