Simple C Shell (SCS) A powerful, custom command-line shell written entirely in C. This project was built from the ground up to demonstrate advanced systems programming concepts, resulting in a feature-rich and functional shell that mimics many capabilities of standard shells like bash.
Features This shell is more than just a simple command executor. It includes a wide array of advanced features that make it a practical tool for daily use.
Core Functionality Command Execution: Executes any command found in the system's PATH.
Pipelines (|): Chains multiple commands together, piping the output of one command to the input of the next.
Example: cat file.txt | grep 'error' | wc -l
I/O Redirection: Redirects standard input (<) and standard output (>).
Example: ls -l > file_list.txt
Conditional Execution (&& and ||): Executes commands based on the success or failure of the previous command.
Example: make && ./my_program
Job Control Background Processes (&): Runs any command or pipeline in the background without blocking the shell.
Full Job Management:
jobs: Lists all current background and stopped jobs.
fg %: Brings a job to the foreground.
bg %: Resumes a stopped job in the background.
Ctrl+Z: Stops the current foreground job.
Customization and Scripting Aliases: Creates shortcuts for longer commands using alias and unalias.
Example: alias ll='ls -l -h'
Shell Variables: Supports shell variables and environment variable expansion.
Example: export MY_VAR="Hello" and echo $MY_VAR
Customizable Prompt (PS1): Allows for a fully customizable prompt string.
Supports \u (user), \h (host), \w (working directory), and $.
Example: export PS1='\u@\h:\w$ '
Startup File (~/.my_shellrc): Automatically loads a configuration file on startup to set permanent aliases and variables.
Script Execution: Can run shell scripts passed as a command-line argument.
User Interface Command History: Navigates through previous commands using the Up and Down arrow keys.
Tab Completion: Provides auto-completion for executables and file paths.
Getting Started Compilation To compile the shell, you will need gcc and the standard C libraries.
gcc -o my_shell simple_shell.c
Running the Shell There are two ways to run the shell:
Interactive Mode: For day-to-day use.
./my_shell
Script Mode: To execute a script file.
./my_shell your_script.sh
Example Usage
- Create a Startup File To customize your shell, create a file at ~/.my_shellrc:
alias ll='ls -l -h' alias ..='cd ..'
export PS1='[\u@\h \w]$ '
The next time you start ./my_shell, these settings will be loaded automatically.
- Example Session Here is a sample session demonstrating some of the shell's features:
[user@hostname ~]$ ll
[user@hostname ~]$ mkdir project && cd project
[user@hostname ~/project]$ echo "Hello, $USER. This is a test." > test.txt
[user@hostname ~/project]$ sleep 20 &
[1] 12345
[user@hostname ~/project]$ jobs
[1] 12345 Running sleep 20
[user@hostname ~/project]$ fg %1
This project was created to explore the depths of C programming and operating system concepts. Enjoy using your powerful new shell!
project by MANAV HOWAL AKA ARES