Portfolio

Own shell

Una shell con un comportamiento exactamente igual a la shell tradicional Bourne Shell. Para la construcción se tuvieron en cuenta conceptos como el flujo de una shell, que son los pid y ppid, cómo manejar procesos en linux, diferencias entre un syscall y una funcion, cómo manipular el entorno y trabajar con el PATH y por supuesto, el manejo cuidadoso de la memoria para evitar fugas.

stack

own shell

User guide

simple_shell project

Description 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.

Usage 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

Built-ins

  • exit & exit(status)
  • env
  • setenv & unsetenv

Examples

  1. 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
$
  1. short command
  • non interactive
$ echo "pwd" | ./hsh
$ /home/davidgonzalezfx/simple_shell
  • interactive mode
$ ./hsh
./hsh$ echo hello world
helo world
./hsh$ exit
$
  1. 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

Full documentation For more info about this project you can run the man page:

$ ./man_1_simple