C - Shell v2
Simple Shell V 2.0 is a project based on the original sh “Borne shell” functionality,
but a small subset and allows us to understand Unix-like OS architecture. It was
developed on Ubuntu Linux and with C language.
The concepts covered here are:
Example:
vagrant@~$
vagrant@~$ git clone https://github.com/gogomillan/shell_v2
vagrant@~$
Example:
vagrant@~$
vagrant@~$ cd shell_v2
vagrant@~$ make all
vagrant@~$ ./hsh
($) ls
addhist.c check_variables.c error_handler.c _help.c _hlphistory.c intfuncs.c myexec.c _setenv.c
alias.c currhist.c _exit.c _history.c hsh loadhist.c path.c sizehist.c
AUTHORS dockerfile _getenv.c _hlpcd.c hsh.h main.c README.md string_funcs.c
_cd.c _env.c _getline.c _hlpexit.c inputfile.c Makefile savehist.c _strtok.c
check_builtin.c env_funcs.c handsigint.c _hlphelp.c interact.c man_1_simple_shell script.sh _unsetenv.c
($) exit
vagrant@~$
This shell work like this in interactive mode:
Example:
vagrant@~$ ./hsh
($) /bin/ls
hsh main.c shell.c
($)
($) exit
vagrant@~$
But also in non-interactive mode:
Example:
vagrant@~$
vagrant@~$ echo "/bin/ls" | ./hsh
hsh main.c shell.c test_ls_2
vagrant@~$
vagrant@~$ cat test_ls_2
/bin/ls
/bin/ls
vagrant@~$
vagrant@~$ cat test_ls_2 | ./hsh
hsh main.c shell.c test_ls_2
hsh main.c shell.c test_ls_2
vagrant@~$
gonza-juan-pc@~$ echo Holberton School > test
gonza-juan-pc@~$ cat -e test
Holberton School$
gonza-juan-pc@~$
gonza-juan-pc@~$ echo Holberton School > test
gonza-juan-pc@~$ cat -e test
Holberton School$
gonza-juan-pc@~$ echo Holberton School 1> test
gonza-juan-pc@~$ cat -e test
Holberton School$
gonza-juan-pc@~$ echo Holberton School 2> test
gonza-juan-pc@~$ cat -e test
gonza-juan-pc@~$ ls /hbtn 2> test
gonza-juan-pc@~$ cat -e test
ls: cannot access /hbtn: No such file or directory$
gonza-juan-pc@~$
gonza-juan-pc@~$ rm -f test
gonza-juan-pc@~$ echo Holberton School >> test
gonza-juan-pc@~$ cat -e test
Holberton School$
gonza-juan-pc@~$ echo Holberton School >> test
gonza-juan-pc@~$ cat -e test
Holberton School$
Holberton School$
gonza-juan-pc@~$
gonza-juan-pc@~$ cat -e small_file
Holberton$
Second line$
gonza-juan-pc@~$ rev < small_file
notrebloH
enil dnoceS
gonza-juan-pc@~$
gonza-juan-pc@~$ cat -e << HOLBERTON
> qwertyuiop
> ls -l
> cat -e small_file
> HOLBERTONnope
> nopeHOLBERTON
> HOLBERTON
> HOLBERTON
qwertyuiop$
ls -l$
cat -e small_file$
HOLBERTONnope$
nopeHOLBERTON$
HOLBERTON $
gonza-juan-pc@~$
gonza-juan-pc@~$ ls /var | rev
spukcab
ehcac
hsarc
bil
lacol
kcol
gol
liam
scirtem
tpo
nur
loops
pmt
gonza-juan-pc@~$ ls -lr /var | cat -e
total 44$
drwxrwxrwt 2 root root 4096 Jul 5 10:26 tmp$
drwxr-xr-x 9 root root 4096 Feb 17 2016 spool$
lrwxrwxrwx 1 root root 4 Nov 19 2016 run -> /run$
drwxr-xr-x 2 root root 4096 Feb 17 2016 opt$
drwxrwsrwt 2 root whoopsie 4096 Feb 17 2016 metrics$
drwxrwsr-x 2 root mail 4096 Feb 17 2016 mail$
drwxrwxr-x 14 root syslog 4096 Jul 11 09:34 log$
lrwxrwxrwx 1 root root 9 Nov 19 2016 lock -> /run/lock$
drwxrwsr-x 2 root staff 4096 Apr 10 2014 local$
drwxr-xr-x 70 root root 4096 Mar 21 13:06 lib$
drwxrwsrwt 2 root whoopsie 4096 Jul 11 14:54 crash$
drwxr-xr-x 17 root root 4096 Feb 17 2016 cache$
drwxr-xr-x 2 root root 4096 Jul 11 09:33 backups$
gonza-juan-pc@~$ echo "Holberton" | wc -
10
gonza-juan-pc@~$
gonza-juan-pc@~$ ls /var ; ls /var
backups cache crash lib local lock log mail metrics opt run spool tmp
backups cache crash lib local lock log mail metrics opt run spool tmp
gonza-juan-pc@~$ ls /hbtn ; ls /var
ls: cannot access /hbtn: No such file or directory
backups cache crash lib local lock log mail metrics opt run spool tmp
gonza-juan-pc@~$ ls /var ; ls /hbtn
backups cache crash lib local lock log mail metrics opt run spool tmp
ls: cannot access /hbtn: No such file or directory
gonza-juan-pc@~$ ls /var ; ls /hbtn ; ls /var ; ls /var
backups cache crash lib local lock log mail metrics opt run spool tmp
ls: cannot access /hbtn: No such file or directory
backups cache crash lib local lock log mail metrics opt run spool tmp
backups cache crash lib local lock log mail metrics opt run spool tmp
gonza-juan-pc@~$
gonza-juan-pc@~$ ls /var && ls /var
backups cache crash lib local lock log mail metrics opt run spool tmp
backups cache crash lib local lock log mail metrics opt run spool tmp
gonza-juan-pc@~$ ls /hbtn && ls /var
ls: cannot access /hbtn: No such file or directory
gonza-juan-pc@~$ ls /var && ls /var && ls /var && ls /hbtn
backups cache crash lib local lock log mail metrics opt run spool tmp
backups cache crash lib local lock log mail metrics opt run spool tmp
backups cache crash lib local lock log mail metrics opt run spool tmp
ls: cannot access /hbtn: No such file or directory
gonza-juan-pc@~$ ls /var && ls /var && ls /var && ls /hbtn && ls /hbtn
backups cache crash lib local lock log mail metrics opt run spool tmp
backups cache crash lib local lock log mail metrics opt run spool tmp
backups cache crash lib local lock log mail metrics opt run spool tmp
ls: cannot access /hbtn: No such file or directory
gonza-juan-pc@~$
gonza-juan-p@~$ ls /var || ls /var
backups cache crash lib local lock log mail metrics opt run spool tmp
gonza-juan-p@~$ ls /hbtn || ls /var
ls: cannot access /hbtn: No such file or directory
backups cache crash lib local lock log mail metrics opt run spool tmp
gonza-juan-p@~$ ls /hbtn || ls /hbtn || ls /hbtn || ls /var
ls: cannot access /hbtn: No such file or directory
ls: cannot access /hbtn: No such file or directory
ls: cannot access /hbtn: No such file or directory
backups cache crash lib local lock log mail metrics opt run spool tmp
gonza-juan-p@~$ ls /hbtn || ls /hbtn || ls /hbtn || ls /var || ls /var
ls: cannot access /hbtn: No such file or directory
ls: cannot access /hbtn: No such file or directory
ls: cannot access /hbtn: No such file or directory
backups cache crash lib local lock log mail metrics opt run spool tmp
gonza-juan-p@~$
Implement the setenv and unsetenv builtin commands
Handle Ctrl+C: your shell should not quit when the user inputs ^C
Juan Marcos Cabezas
Gonzalo Gomez Millan
MIT License LICENSE