In simple_shell project we code from zero our own custom printf function. Our shell must have the same behavior than sh shell in output and error. We had to learn about the workflow of a command line interpreter, what's a pid and ppid, learn about manage processes, how to manipulate the environment of the current process, the difference between a function and system call, how to create processes, how to get PATH variables, execute commands with execve. And off course be carefull with memory leaks and write beautiful code with Betty style.
First, you have to clone this repo $git clone https://github.com/davidgonzalezfx/simple_shell.git
Compile
gcc -Wall -Werror -Wextra -pedantic *.c -o executable_filename
Execute: see more in examples
Interactive mode:
$ ./hsh
./hsh$ [put_commands and_arguments]
Non-interactive mode
$ echo "[put_commands and_arguments]" | ./hsh
- exit & exit(status)
- env
- setenv & unsetenv
- Absolute path commands
- non interactive
$ echo "/bin/pwd" | ./hsh
$ /home/davidgonzalezfx/simple_shell
- interactive mode
$ ./hsh
./hsh$ /bin/echo hello world
helo world
./hsh$ exit
$
- short command
- non interactive
$ echo "pwd" | ./hsh
$ /home/davidgonzalezfx/simple_shell
- interactive mode
$ ./hsh
./hsh$ echo hello world
helo world
./hsh$ exit
$
- built-ins
- non interactive
$ echo "exit" | ./hsh
$ echo $?
0
- interactive mode
$ ./hsh
./hsh$ exit 98
$ echo $?
98
Some error output
$ ./hsh
./hsh$ ls /non_existing_folder
ls: cannot access '/non_existing_folder': No such file or directory
./hsh$ exit
$ echo $?
2
$ echo "non_valid_command" | ./hsh
./hsh: 1: non_valid_command: not found
$ echo $?
127
File | Description |
---|---|
AUTHORS | File with names of the owners and authors of this project |
Readme.md | Nutshell description of simple_shell project |
aux_funs.c | Auxiliar functions signal_exit: handler for SIGINT signals _calloc: allocate memory and fills it with zeros |
built-ins.c | Built-ins functions: check_word: evalute alpha chars in string exit_built_in: stop execution of shell env_built_in: prints environment variables |
core_funs.c | Heart of simple_shell check_builtin: check if first argument is a built-int not_found_error: handler for print error when command is not found simple_exec: decision flow for command execution |
path_funs.c | Function to check command in path _getenv: search variable in environment vars cmd_path: concat first argument with PATH dirs |
shell.h | Header file All includes All prototypes Definition of struct params |
simple_shell.c | Initialize the simple_shell execution: test: Remove \n last char readed with getline Tokenize and save in argv all arguments readed Calls simple_exec main: Initialize params struct vars Set signal listenes Print prompt (interactive mode) Read arguments with getline Handle CTRL + D to stop execution |
string_funs.c | First string functions file _strcat: concat string (no malloc) _strlen: get length of string rev_string: reverse a string _itoa: convert int to string _strcmp: compare two strings |
string_funs2.c | Second string functions file _strchr: search char in string _strcpy: copy string in other one str_concat: concat string (malloc) _atoi: convert string num, to int |
For more info about this project you can run the man page:
$ ./man_1_simple
Go to this link to see the flowchart of our project: flow chart
David Gonzalez - @davidgonzalezfx
Nicolas Forero - @nsforero10