Skip to content

godfreydekew/simple_shell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Shell (HSH)

Shell Illustration


Overview

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.


Features

  • 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 PATH environment 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.

Built-in Commands

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.

Installation

  1. Clone the repository:

    git clone https://github.com/godfreydekew/simple_shell.git
    cd simple_shell
  2. Compile the project:

    make

Usage

Run the shell by executing:

./bin/myshell

You will see the prompt:

#cisfun$

Now you can enter commands just like in a standard shell:

Example Session

#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 0

Clean up

make clean

About

ALX simple shell project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors