Skip to content

Sanika810/Custom-Linux-Command-Shell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 

Repository files navigation

Custom Shell in C

This project is a custom shell implementation in C that supports standard shell commands, sequential and parallel execution, I/O redirection, and pipelines. It also handles signals (Ctrl+C, Ctrl+Z) gracefully and provides a basic interactive prompt.


✨ Features

  • Basic command execution

    • Runs external commands like ls, pwd, echo, etc.

    • Built-in support for:

      • cd (change directory)
      • exit (terminate the shell)
  • Sequential execution (##)

    • Commands separated by ## run one after another.
    ls ## pwd ## date
  • Parallel execution (&&)

    • Commands separated by && run in parallel.
    ls && date && echo "Done"
  • Output redirection (>)

    • Redirects standard output of a command to a file.
    ls > out.txt
  • Pipelines (|)

    • Connects multiple commands with pipes.
    ls -l | grep ".c" | wc -l
  • Signal handling

    • Ctrl+C (SIGINT) and Ctrl+Z (SIGTSTP) don’t kill the shell β€” they just refresh the prompt.

πŸ“‚ Project Structure

.
β”œβ”€β”€ myshell.c       # Main source code
└── README.md     # Documentation

βš™οΈ Compilation

Use gcc to compile:

gcc myshell.c -o myshell

πŸš€ Usage

Run the shell:

./myshell

You’ll see a prompt showing the current directory:

/home/user$

Examples:

/home/user$ ls
/home/user$ cd Documents
/home/user/Documents$ ls && date
/home/user/Documents$ ls ## pwd
/home/user/Documents$ ls -l | grep ".txt"

🧩 Implementation Details

  • Parsing

    • Custom parseInput() function to tokenize input by delimiters (&&, ##, >, |).
  • Execution

    • Uses fork(), execvp(), and waitpid() for process handling.
  • Parallel Execution

    • Forks multiple processes and waits for all.
  • Sequential Execution

    • Executes commands one after another.
  • Redirection

    • Uses open(), dup2() to redirect standard output.
  • Pipelines

    • Sets up multiple pipes and forks processes in a chain.
  • Signal Handling

    • Catches SIGINT and SIGTSTP to refresh the prompt instead of terminating the shell.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages