This is a command line interpreter, or shell, in the tradition of the first Unix shell written by Ken Thompson in 1971. This was made as a project for Holberton School. In this project we apply the knowledge that we have learned in C programming language. Standard functions and system calls employed in simple_shell include:
access, execve, exit, fork, free, malloc, read, signal, wait, write.- AUTHORS - List of contributors to this repository
- man_1_simple_shell - Manual page for the simple_shell
- shell.h - program header file
- coincidence.c -
coincidence- looks for coincidenceext- free and exit bufferenv- prints environcompare_path- compare PATH in environstr_concate- concates two strings
- free.c - function related to free
freeAll- frees a bufferchecks- writes to standar error
- exit.c - fuction related to exit
sigintHandler- signal errorfree_env- frees the shell's environment
- getargs.c - funtion creates an array of pointers
count- counts the buffergetargs- creates arrays of ponters with all the arguments
- get_env.c - enviromental variables related function
get_env- gets an environ charget_pwd- creates a pointer of the pathget_env1- get a specific pointer from env
- _strtok.c - custom strtok
_strtok- checks if a character matches in a string and breaks it into tokens
- getline1.c - functions related to get a line
store_lineptr- aasigns the linegetline1- reads imput from a stream
- prompt.c - essential functions to the shell
prompt- prints a prompt
- spaces.c - functions related to string manipulation
spaces- compare size of stringcpstring- duplicates a stringcd_fun- cd functionchangepwd- change pwd and old pwdoldpwd- get oldpwd
- shell.c - main function of the shell
main- the main function of the programret- return functionextstatus- return statuswriteexe- writes to standar errorwrites0- writes to standar error
- calloc.c - allocates memory
calloc- allocates memory and return a pointers
- realloc.c - reallocates memory
calloc- reallocates memory and return a pointers
- strcpy.c - copies string to buffer
strcpy- copies string to buffer
- aux.c - auxiliar functions to print
strlen- returns the length of a string_puts- writes a string to standard output_puts2- writes a string to standard errounatoi- converts an unsigned int to a stringwrites3- writes to estandar error
simple_shell is designed to run in the Ubuntu 14.04 LTS linux environment and to be compiled using the GNU compiler collection v. gcc 4.8.4 with flags-Wall, -Werror, -Wextra, and -pedantic.
- Clone this repository:
git clone "https://github.com/zamu5/simple_shell.git" - Change directories into the repository:
cd simple_shell - Compile:
gcc -Wall -Werror -Wextra -pedantic *.c -o hsh - Run the shell in interactive mode:
./hsh - Or run the shell in non-interactive mode: example
echo "pwd" | ./hsh
The simple_shell is designed to execute commands in a similar manner to sh, however with more limited functionality. The development of this shell is ongoing. The below features will be checked as they become available (see man page for complete information on usage):
- uses the PATH
- implements builtins
- handles command line arguments
- custom strtok function
- uses exit status
- shell continues upon Crtl+C (^C)
- handles comments (#)
- handles ;
- custom getline type function
- handles && and ||
- aliases
- variable replacement
- exit
- env
- setenv
- unsetenv
- cd
- help
- history
Run the executable in your terminal after compiling:
$ ./hsh
$ ls -la
total 116
drwxrwxr-x 3 vagrant vagrant 4096 Aug 25 20:21 .
drwxr-xr-x 14 vagrant vagrant 4096 Aug 25 20:27 ..
drwxrwxr-x 8 vagrant vagrant 4096 Aug 25 20:27 .git
-rw-rw-r-- 1 vagrant vagrant 160 Aug 25 00:09 AUTHORS
-rw-rw-r-- 1 vagrant vagrant 2828 Jul 31 01:52 README.md
-rw-rw-r-- 1 vagrant vagrant 823 Aug 23 16:54 _strtok.c
-rw-rw-r-- 1 vagrant vagrant 1967 Aug 24 16:46 coincidence.c
-rw-rw-r-- 1 vagrant vagrant 216 Aug 23 16:54 concidence.c~
-rw-rw-r-- 1 vagrant vagrant 241 Aug 23 16:54 exit.c
-rw-rw-r-- 1 vagrant vagrant 189 Aug 23 16:54 free.c
-rw-rw-r-- 1 vagrant vagrant 338 Aug 24 16:46 get_env.c
-rw-rw-r-- 1 vagrant vagrant 1117 Aug 23 18:42 getargs.c
-rw-rw-r-- 1 vagrant vagrant 1477 Aug 25 20:21 getline1.c
-rw-rw-r-- 1 vagrant vagrant 1302 Aug 24 16:46 holberton.h
-rwxrwxr-x 1 vagrant vagrant 29371 Aug 24 16:56 hsh
-rw-rw-r-- 1 vagrant vagrant 2271 Aug 25 02:52 man_1_simple_shell
-rw-rw-r-- 1 vagrant vagrant 167 Aug 23 16:54 prompt.c
-rw-rw-r-- 1 vagrant vagrant 789 Aug 23 18:47 realloc.c
-rw-rw-r-- 1 vagrant vagrant 973 Aug 24 16:51 shell.c
-rw-rw-r-- 1 vagrant vagrant 527 Aug 24 16:46 spaces.c
-rw-rw-r-- 1 vagrant vagrant 270 Aug 23 18:48 strcpy.c
-rw-rw-r-- 1 vagrant vagrant 46 Aug 23 16:54 test
At this time, there are no known bugs.
