Skip to content

vivekjutture/Linux-Shell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’» My Shell β€” Minimal Production-Level Shell

A compact, educational Unix-style shell written in C with common features useful for learning and small scripting tasks.

Highlights

  • Builtins: cd, exit, history, export πŸ”§
  • Pipelines: | support for chaining commands πŸ”—
  • Redirection: input <, output > and append >> πŸ”
  • Background execution: run jobs with & βš™οΈ
  • Variable expansion: $VAR is expanded using environment variables πŸ’‘
  • Script execution: run shell scripts by passing a filename
  • Signal handling: graceful Ctrl+C handling (SIGINT) πŸ›‘οΈ

Why this project?

  • Great for learning process control, fork(), execve()/execvp(), pipes, and basic shell features.
  • Minimal, contained implementation β€” useful as a teaching aid or starting point for enhancements.

Build

On Linux / WSL / macOS (recommended):

gcc -o myshell My_Shell.c

On Windows (use WSL, MinGW, or MSYS2):

  • With MinGW (example):
gcc -o myshell.exe My_Shell.c

Notes: Some platform differences (signals, /dev/null, path behavior) may exist on native Windows β€” WSL provides the closest behavior to Unix.

Run

Interactive shell:

./myshell        # or myshell.exe on Windows

Run a script file:

./myshell myscript.sh

Usage Examples

  • Change directory:
cd /path/to/dir
  • See command history:
history
  • Pipeline example:
ls -la | grep ".c" | sort
  • Redirect output and append:
echo "hello" > out.txt
cat file.txt >> out.txt
  • Run in background:

    sleep 10 &
  • Export environment variable:

    export MYVAR=hello
    echo $MYVAR

Implementation notes (quick)

  • Parsing: strtok()-based splitting on spaces; simple and intentional for clarity.
  • Redirection: handled by scanning args and dup2() before execvp().
  • Pipelines: splits on |, uses pipe() + multiple fork()s.
  • History: in-memory history[] array (no file persistence).

Limitations & TODO

  • Quoting and escaped spaces are not fully supported.
  • No command-line editing (no readline support).
  • No persistent history file.
  • Limited error handling for malformed input.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages