HSH is a simple Unix-like shell implemented in C, inspired by the classic Thompson Shell. It aims to provide core shell functionalities while helping users understand how shells work internally.
- Interactive Prompt: Displays a prompt (
#cisfun$) and waits for user input. - Command Execution: Supports running executables with arguments.
- Error Handling: Prints informative error messages when commands fail or cannot be found.
- EOF Handling: Properly handles the End-of-File (Ctrl+D) input to exit gracefully.
- PATH Support: Searches executable paths based on the
PATHenvironment variable. - Signal Handling: Captures
Ctrl-C(SIGINT) to avoid shell termination. - Command Separators: Supports command chaining using
;. - Logical Operators: Handles
&&and||for conditional command execution. - Variable Replacement: Expands special variables like
$?(last exit status) and$$(process ID). - Comments: Supports inline comments starting with
#. - File Input: Can execute commands from a file input.
| Command | Description |
|---|---|
exit [n] |
Exit the shell, optionally specifying an exit status n. |
env |
Print the current environment variables. |
setenv [var] [val] |
Set or update an environment variable. |
unsetenv [var] |
Remove an environment variable. |
cd [dir] |
Change the current working directory. |
help [builtin] |
Display documentation about built-in commands. |
-
Clone the repository:
git clone https://github.com/godfreydekew/simple_shell.git cd simple_shell -
Compile the project:
make
Run the shell by executing:
./bin/myshellYou will see the prompt:
#cisfun$
Now you can enter commands just like in a standard shell:
#cisfun$ /bin/ls -l /etc
total 12
-rw-r--r-- 1 root root 1234 Jul 25 10:00 hosts
-rw-r--r-- 1 root root 4321 Jul 24 15:00 passwd
#cisfun$ cd /usr/local
#cisfun$ pwd
/usr/local
#cisfun$ setenv GREETING HelloShell
#cisfun$ echo $GREETING
HelloShell
#cisfun$ unsetenv GREETING
#cisfun$ env
PATH=/usr/local/bin:/usr/bin:/bin
HOME=/home/user
...
#cisfun$ exit 0make clean