:shell: A Unix shell written in C.
This a Unix shell similar to sh
, bash
and zsh
.
This implementation is not based on (or exploit) another shell. For example, system(3)
.
cd
and exit
following built-in commandvalgrind
checks, as well as gcc -Wall -Wextra
.set
and unset
built-ins for managing environment variables.PROMPTING
in the bash(1)
manual page)bg
to continue a job in the background, and fg
to recall a job to the foreground.
## simple commands:
ls
sleep 5 # must not show the prompt too early
## simple commands, with built-ins:
mkdir t
cd t
/bin/pwd # must show the new path
exit 42 # terminate with code
## sequences:
echo hello; echo world # must print in this order
exit 0; echo fail # must not print "fail"
## pipes:
ls | grep t
ls | more # must not show prompt too early
ls | sleep 5 # must not print anything, then wait
sleep 5 | ls # must show listing then wait
ls /usr/lib | grep net | cut -d. -f1 | sort -u
## redirects:
>dl1 ls /bin; <dl1 wc -l
>dl2 ls /usr/bin; >>dl1 cat dl2 # append
<dl2 wc -l; <dl1 wc -l # show the sum
>dl3 2>&1 find /var/. # errors redirected
## detached commands:
sleep 5 & # print prompt early
{ sleep 1; echo hello }& echo world; sleep 3 # invert output
## sub-shell:
( exit 0 ) # top shell does *not* terminate
cd /tmp; /bin/pwd; ( cd /bin ); /bin/pwd # "/tmp" twice
## environment variables
set hello=world; env | grep hello # prints "hello=world"
(set top=down); env | grep top # does not print "top=down"
# custom PATH handling
mkdir /tmp/hai; touch /tmp/hai/waa; chmod +x /tmp/hai/waa
set PATH=/tmp/hai; waa # OK
unset PATH; waa # execvp() reports failure
Built-in: cd <path>
: Change the current directory to become the directory specify in the argument. Your shell does not need to support the syntax cd
without arguments like Bash does.
Built-in: exit <code>
: Terminate the current shell process using the specified numeric code. Your shell does not need to support the syntax exit
without arguments like Bash does.
Built-in (advanced): set <var>=<value>
: Set the specified environment variable. Your shell does not need to support the syntax set
without arguments like Bash does.
Built-in (advanced): unset <var>
(optional)
: Unset the specified environment variable.
This shell might encounter two types of error:
execvp(2)
fails to find an executable program For these errors, this shell will print a usefu error message on its standard error. The helpe function perror(3)
is used for this purpose.ls > foo
and >foo ls
are normally equivalent. However, this shell only supports >foo ls
.
exit 42 # closes the shell
exit 42 | sleep 1 # exit in sub-shell, main shell remains
cd /tmp # changes the directory
cd /tmp | sleep 1 # change directory in sub-shell
# main shell does not
install dependencies on Ubuntu using the following command:
sudo apt install build-essential python python-pexpect libreadline-dev flex valgrind
make check
to run tests.