Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

C - Shell : A Bash Shell

A custom shell implemented in C with support for built-in commands, external command execution, pipes, redirection, background jobs, history, and process management utilities.

Overview

This shell replicates common Bash-like behavior and includes several custom built-in commands. It supports:

  • prompt display with username and system hostname
  • multiple commands separated by ;
  • background execution using &
  • pipes with |
  • input/output redirection using > and >>
  • built-in commands for filesystem navigation, file display, process inspection, and command history
  • external commands such as cat, echo, sleep, and more

Features

  • Clear prompt with current user and hostname
  • Handles multiple commands in one line
  • Supports background processes and job control
  • Supports pipes and output redirection
  • History file saved in the user's home directory
  • Custom commands for shell-specific utilities

Built-In Commands

hop

Change the current working directory.

  • hop [directory] : Move to the specified directory.
  • hop - : Switch back to the previous directory.
  • hop .. : Move up one directory.
  • hop ~ : Change to the user's home directory.

reveal

Display a directory listing or file contents.

  • reveal [path] : Show the contents of the specified path.
  • reveal -a [path] : Include hidden files in the listing.
  • reveal -l [path] : Show detailed information, including permissions, owner, size, and modification date.
  • reveal -la [path] or reveal -al [path] : Combined detailed listing and hidden files.

Example:

reveal -l -a /path/to/directory

log

Manage shell command history.

  • log : Print stored command history.
  • log purge : Clear command history.
  • log execute [n] : Re-run the nth command from history.

proclore

Inspect process information.

  • proclore : Show information for the current shell process.
  • proclore [pid] : Show information for the given process ID.

seek

Search for files or directories by prefix.

  • seek [name] : Search for matching files and directories in the current directory tree.
  • seek -f [name] : Search only files.
  • seek -d [name] : Search only directories.
  • seek -e [name] : When exactly one match is found, display the file or change into the directory.
  • seek [flags] [name] [directory] : Search starting from the specified directory.

Example:

seek -d -e mydir .

activities

List processes spawned by this shell.

  • activities : Display managed background and stopped processes.

iMan

Fetch online manual pages for commands.

  • iMan [command_name] : Retrieve the manual page for the specified command.

Example:

iMan ls

neonate

Monitor the most recently created process.

  • neonate -n <seconds> : Print the latest created PID every <seconds> seconds until x is pressed.

Example:

neonate -n 5

fg and bg

Control background and stopped processes.

  • fg <pid> : Bring the specified process to the foreground.
  • bg <pid> : Resume the specified stopped process in the background.

exit

Quit the shell.

  • exit : Exit the custom shell program.

Usage

Use the shell prompt to enter commands. Examples:

ls -l
hop ~/projects
reveal -la .
log
log execute 3
seek -f notes.txt .
proclore 1234
sleep 5 &
cat file.txt | grep hello > out.txt
fg 4321
bg 4321
neonate -n 2

Multiple commands on a single line:

hop /tmp; ls -l; echo done

Sample Session

$ ./a.out
[amisha@machine ~]$ hop /tmp
[amisha@machine /tmp]$ reveal -l
 drwxr-xr-x  2 user group  4096 Jun 23 10:00 example/
-rw-r--r--  1 user group   123 Jun 23 10:01 notes.txt
[amisha@machine /tmp]$ seek -f notes.txt .
./notes.txt
[amisha@machine /tmp]$ cat notes.txt | grep hello > out.txt
[amisha@machine /tmp]$ log
hop /tmp
reveal -l
seek -f notes.txt .
cat notes.txt | grep hello > out.txt
[amisha@machine /tmp]$ sleep 5 &
[amisha@machine /tmp]$ activities 
sleep 12345 Running
[amisha@machine /tmp]$ fg 12345
[amisha@machine /tmp]$ exit

Build and Run

Build the project with the provided Makefile:

make
./a.out

Or build and run in one step:

make run

Clean the executable:

make clean

Notes

  • External system commands are executed when the command is not recognized as a built-in.
  • log commands are excluded from history to prevent recursive history entries.
  • seek -e only acts when exactly one match is found.
  • Background commands use & and may be managed by fg/bg.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages