This project is a UNIX command line interpreter, also known as a shell. It provides a command line interface where users can enter commands to be executed. The shell reads the commands, executes them, and displays the results to the user.
To use the shell, you can run the ./hsh
executable. Once started, the shell will display a prompt and wait for the user to enter a command. The prompt is displayed after each command execution.
The shell supports simple command lines. It handles advanced features such as semicolons, pipes, redirections, or special characters.
If an executable cannot be found, the shell will print an error message and display the prompt again.
The shell can be used in both interactive and non-interactive mode:
In interactive mode, you can directly enter commands into the shell's prompt:
$ ./simple_shell
($) /bin/ls
file1.txt file2.txt directory
($)
($) exit
$
In non-interactive mode, you can pass commands to the shell through standard input (e.g., using pipes or input redirection):
$ echo "/bin/ls" | ./simple_shell
file1.txt file2.txt directory
To compile the shell, you can use the following command:
gcc -Wall -Werror -Wextra -pedantic -std=gnu89 *.c -o hsh
- Displays a prompt and waits for the user to enter a command.
- Executes the command and displays the output.
- Handles errors when an executable cannot be found.
- Handles the "end of file" condition (Ctrl+D) to exit the shell.
- Handles command lines with arguments. Commands can have additional words as arguments.
- Supports executing commands located in the PATH environment variable.
- Does not call fork if the command does not exist.
- Handles the PATH environment variable for command execution.
- Does not call fork if the command does not exist.
- Implements the built-in exit command to exit the shell.
- Implements the built-in env command to print the current environment.
- Implements a custom getline function to read input from the user.
- Does not use the strtok function for parsing command lines.
- Handles arguments for the built-in exit command, allowing users to specify an exit status.
- Implements the built-in setenv and unsetenv commands to manage environment variables.
- Implements the built-in cd command to change the current directory.
- Handles the ; separator to execute multiple commands in sequence.
- Handles the && and || operators for conditional command execution.
The shell is implemented using a set of allowed functions and system calls, including but not limited to:
- access
- chdir
- close
- closedir
- execve
- exit
- _exit
- fflush
- fork
- free
- getcwd
- getline
- getpid
- isatty
- kill
- malloc
- open
- opendir
- perror
- read
- readdir
- signal
- stat (__xstat)
- lstat (__lxstat)