This is an executable minishell that runs a basic shell program !!
The shell implements cd and exit as built-ins, includes signal handling, and uses fork/exec for all other commands.
The program is called from the command line and takes no arguments.
When called, the program prints the current working directory and waits for user input.
Directory names are printed in BRIGHTBLUE \x1b[34;1m.
$ ./minishell
[/home/user/minishell]$
cd and exit are manually implemented commands in this shell. All others use exec.
-
cdIf
cdis called with no arguments or the one argument ~, it changes the working directory to the user's home directory (not hard coded). This also works with ~ followed by trailing directory names, like cd ~/Downloads.If
cdis called with one argument that isn't ~, it attempts to open the directory specified in that argument.Additionally,
cdsupports changing into a directory whose name contains spaces. These directory names must be enclosed in double spaces, such as:cd "some folder name" cd "some"" folder ""name"If a quote is missing (i.e. cd "Downloads), an error message is displayed and the program exits in failure.
-
exitThe
exitcommand causes the shell to terminate and returnEXIT_SUCCESS. Usingexitis the only way to stop shell's execution normally. -
exec
All other commands are executed using
exec. When an unknown command is entered, the program forks. The child program will exec the given command and the parent process will wait for the child process to finish before returning to the prompt.Commands are bounded at 4096 characters including '\0', and line tokens 2048 (including trailing NULL).
Errors for the system/function calls are handled using strerror(errno).
The shell exits gracefully varying error scenarios with a detailed error message.
When the minishell captures the SIGINT signal, it returns the user to the prompt. Interrupt signals generated
in the terminal are delivered to the active process group, which includes both parent and child processes.
The child will then receive the SIGINT and handle it accordingly.
$ ./minishell
[/home/user/minishell]$ echo HI
HI
[/home/user/minishell]$ cd ..
[/home/user]$ cd minishell
[/home/user/minishell]$ cd /tmp
[/tmp]$ cd ~
[/home/user]$ cd minishell
[/home/user/minishell]$ ls
Makefile minishell minishell.c
[/home/user/minishell]$ pwd
/home/user/minishell
[/home/user/minishell]$ cd
[/home/user]$ pwd
/home/user
[/home/user]$ nocommand
Error: exec() failed. No such file or directory.
[/home/user]$ cd minishell
[/home/user/minishell]$ ^C
[/home/user/minishell]$ sleep 10
^C
[/home/user/minishell]$ exit
$