Skip to content

0x4r35/c-shell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

c-shell

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

  1. Create a Startup File To customize your shell, create a file at ~/.my_shellrc:

~/.my_shellrc

My favorite aliases

alias ll='ls -l -h' alias ..='cd ..'

Set a custom prompt

export PS1='[\u@\h \w]$ '

The next time you start ./my_shell, these settings will be loaded automatically.

  1. Example Session Here is a sample session demonstrating some of the shell's features:

Start the shell. The custom prompt from .my_shellrc should appear.

[user@hostname ~]$ ll

The 'll' alias is executed.

[user@hostname ~]$ mkdir project && cd project

Creates a directory and enters it only if creation was successful.

[user@hostname ~/project]$ echo "Hello, $USER. This is a test." > test.txt

Uses variable expansion and output redirection.

[user@hostname ~/project]$ sleep 20 &

Runs a job in the background.

[1] 12345

[user@hostname ~/project]$ jobs

Lists the running sleep job.

[1] 12345 Running sleep 20

[user@hostname ~/project]$ fg %1

Brings the sleep job to the foreground and waits for it to finish.

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages