Skip to content

Custom shell program that supports various features. The shell provides an interactive environment for running commands similar to standard Unix shells.

Notifications You must be signed in to change notification settings

Dorshir/myshell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Custom Shell Program

Overview

This is a custom shell program written in C that supports various features such as command execution, redirection, background execution, built-in commands, variable handling, and more. The shell provides an interactive environment for running commands similar to standard Unix shells.

Features

  1. Basic Command Execution: Execute standard Unix commands with arguments.
  2. Redirection:
    • Output redirection (>)
    • Append redirection (>>)
    • Error redirection (2>)
  3. Background Execution: Run commands in the background using &.
  4. Built-in Commands:
    • Change prompt (prompt =)
    • Print arguments (echo)
    • Change directory (cd)
    • Print the last command status (echo $?)
    • Exit the shell (quit)
    • Repeat the last command (!!)
  5. Signal Handling: Custom message on Control-C.
  6. Pipes: Chain multiple commands with |.
  7. Variable Handling: Set and use custom variables.
  8. Flow Control: Support for if/else statements.
  9. User Input: Read user input and use it in commands.
  10. Command History: Navigate through command history using arrow keys.

Compilation

To compile the shell program, use the following command:

make

Usage

To run the shell, execute:

./myshell

Examples

Basic Commands and Redirection

hello: ls -l
hello: ls -l > file
hello: ls -l >> file
hello: ls no_such_file 2> error.log

Built-in Commands

hello: prompt = myprompt
myprompt: echo abc xyz
myprompt: echo $?
myprompt: cd mydir
myprompt: pwd
myprompt: !!
myprompt: quit

Background Execution

hello: sleep 5 &

Using Variables

hello: $filename = "testfile.txt"
hello: echo "This is a test" > $filename
hello: cat $filename

Read Command

hello: echo Enter your name:
hello: read username
hello: echo "Hello, $username!"

Flow Control (If/Else)

hello: if grep -q "pattern" file.txt
hello: then
hello: echo "Pattern found"
hello: else
hello: echo "Pattern not found"
hello: fi

Piping Commands

hello: cat file.txt | grep "search" | sort | uniq

Notes:

  • Use Ctrl + C to test the custom signal handling(eliminate child processes but not the parent).
  • Navigate through command history using the up and down arrow keys.
  • The if command is actuallize in one row(as in the examples above).

About

Custom shell program that supports various features. The shell provides an interactive environment for running commands similar to standard Unix shells.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published