A lightweight Unix-like shell implementation in C with support for command execution, pipelines, and file redirection.
https://github.com/MaxwellKnight/shell.git
A simple Unix-like shell implementation in C with support for command execution, pipelines, file redirection, and built-in commands.
| operator< and > operatorscd: Change directoryexit: Exit the shellhistory: Display command historytree: Display file system tree structuremain.c: Entry point for the shell programshell.h: Header file containing data structures and function declarationsshell.c: Implementation of shell functionalitycolors.h: Color definitions for terminal outputThe Command structure represents a single command in the shell:
typedef struct Command {
int argc; // Number of arguments
char *name; // Command name
char *argv[MAX_ARGS]; // Command arguments
bool is_out_redirect; // Flag for output redirection
bool is_in_redirect; // Flag for input redirection
char *in_file_name; // Input file name
char *out_file_name; // Output file name
struct Command *next; // Pointer to next command in pipeline
} Command;
The History structure maintains command history:
typedef struct History {
char *history[HISTORY_LEN]; // Array of history entries
int start; // Start index
int count; // Count of entries
int index; // Current index
} History;
Command structures is createdcd: Changes the current working directoryexit: Exits the shellhistory: Displays command history from history.txttree: Displays a tree visualization of the current directory structure<): Redirects input from a file>): Redirects output to a filePipes are implemented using the pipe() system call and connecting the output of one command to the input of the next command.
Compile the shell with:
gcc -o myshell main.c shell.c -std=c99
Run the shell:
./myshell
ls -la
ls -la | grep ".txt" | wc -l
ls -la > output.txt
cat < input.txt
cd /path/to/directory
tree
history
exit