A two-phase implementation of a custom Unix-like shell with local and remote execution capabilities.
- Overview
- Features
- Project Structure
- Prerequisites
- Installation
- Usage
- Phase 1: Local Shell
- Phase 2: Remote Shell
- Supported Commands
- Examples
- Technical Details
- Testing
- Contributing
- License
This project implements a custom command-line shell in C with two phases:
- Phase 1: A local shell that replicates standard Unix shell features
- Phase 2: A remote shell with client-server architecture using socket communication
The implementation demonstrates core systems programming concepts including process management, inter-process communication, file I/O, and network programming.
- โ 15+ built-in commands (ls, cd, pwd, mkdir, rm, etc.)
- โ External command execution (any system command)
- โ Pipe support (single, double, and triple pipes)
- โ File and directory operations
- โ Error handling and validation
- Local command-line interface
- Interactive shell prompt
- Command parsing and execution
- Process creation with fork/exec
- Client-server architecture
- Remote command execution via TCP sockets
- Output capture and network transmission
- Multiple command support over network
- Graceful connection handling
custom-shell/
โโโ phase1/
โ โโโ phase1.c # Local shell implementation
โ โโโ Makefile # Build file for phase 1
โโโ phase2/
โ โโโ server.c # Remote shell server
โ โโโ client.c # Remote shell client
โ โโโ Makefile # Build file for phase 2
โ โโโ test_phase2.sh # Automated test script
โโโ docs/
โ โโโ PHASE1_GUIDE.md # Phase 1 documentation
โ โโโ PHASE2_GUIDE.md # Phase 2 documentation
โ โโโ COMPARISON.md # Phase 1 vs Phase 2 comparison
โโโ README.md # This file
โโโ LICENSE # MIT License
- Operating System: Linux (Ubuntu, Debian, Fedora, etc.) or macOS
- Compiler: GCC (GNU Compiler Collection)
- Build Tools: Make
- Development Headers: Standard C library development files
sudo apt-get update
sudo apt-get install build-essential gcc makexcode-select --install- Clone the repository:
git clone https://github.com/yourusername/custom-shell.git
cd custom-shell- Build Phase 1:
cd phase1
make- Build Phase 2:
cd ../phase2
makecd phase1
./phase1You'll see:
===========================================
Custom Shell - Phase 1
Type 'help' for available commands
Type 'exit' to quit
===========================================
myshell>
Terminal 1 - Start Server:
cd phase2
./serverTerminal 2 - Start Client:
cd phase2
./clientOr connect to a remote server:
./client 192.168.1.100Phase 1 implements a local command-line shell with the following capabilities:
- Interactive command prompt
- Built-in command execution
- External program execution
- Command pipelining (up to 3 pipes)
- File and directory manipulation
Example Session:
myshell> pwd
/home/user/custom-shell
myshell> ls -l
-rw-r--r-- 1 user user 1234 Jan 01 12:00 file.txt
drwxr-xr-x 2 user user 4096 Jan 01 12:00 testdir
myshell> echo Hello World | wc -w
2
myshell> exit
Exiting shell...See docs/PHASE1_GUIDE.md for detailed documentation.
Phase 2 extends Phase 1 with network capabilities using a client-server architecture:
- Server: Executes commands and captures output
- Client: Sends commands and displays results
- Communication: TCP sockets on port 8080
- Protocol: Simple text-based message passing
Architecture:
โโโโโโโโโโโ Network โโโโโโโโโโโ
โ Client โ โโโโโโโโโโโโโโโโโโโโโโโโบ โ Server โ
โ (I/O) โ Commands/Results โ (Exec) โ
โโโโโโโโโโโ โโโโโโโโโโโ
See docs/PHASE2_GUIDE.md for detailed documentation.
| Command | Description | Example |
|---|---|---|
cd |
Change directory | cd /home/user |
pwd |
Print working directory | pwd |
echo |
Print text | echo Hello World |
ls |
List directory contents | ls -l |
mkdir |
Create directory | mkdir newdir |
rmdir |
Remove empty directory | rmdir olddir |
rm |
Remove file/directory | rm file.txt or rm -r dir |
touch |
Create empty file | touch newfile.txt |
cat |
Display file contents | cat file.txt |
clear |
Clear screen | clear |
help |
Show help message | help |
exit |
Exit shell | exit |
Any system command available on your PATH:
whoami,hostname,date,unamegrep,awk,sed,sortwc,head,tail,cut- And many more...
# Single pipe
command1 | command2
# Double pipe
command1 | command2 | command3
# Triple pipe
command1 | command2 | command3 | command4# Navigate and list
myshell> cd /tmp
myshell> pwd
/tmp
myshell> ls -l
# File operations
myshell> touch test.txt
myshell> echo "Hello World" > test.txt
myshell> cat test.txt
Hello World# Count files in directory
myshell> ls | wc -l
# Search in file
myshell> cat /etc/passwd | grep root
# Complex pipeline
myshell> ps aux | grep bash | awk '{print $2}' | wc -l# On client
remote-shell> ls /home
remote-shell> cat /etc/hostname
remote-shell> df -h | grep /dev-
Process Management
fork()- Create child processesexecvp()- Execute programswaitpid()- Wait for child completion
-
Inter-Process Communication
pipe()- Create pipes for data flowdup2()- Duplicate file descriptors- File descriptor manipulation
-
Network Programming (Phase 2)
socket()- Create network endpointsbind(),listen(),accept()- Server setupconnect()- Client connectionsend(),recv()- Data transmission
-
File Operations
opendir(),readdir()- Directory traversalstat()- File informationmkdir(),rmdir(),unlink()- File system operations
- Command Pattern: Each command is encapsulated in its own function
- Chain of Responsibility: Pipeline processing with multiple commands
- Client-Server Pattern: Phase 2 architecture
- Facade Pattern: Simple interface over complex system calls
cd phase2
chmod +x test_phase2.sh
./test_phase2.sh# Test basic commands
ls
pwd
echo test
# Test pipes
ls | grep .c
cat file.txt | wc -l
ps aux | grep bash | wc -l
# Test file operations
mkdir testdir
cd testdir
touch file.txt
cat file.txt
cd ..
rm -r testdir- โ Basic built-in commands
- โ File and directory operations
- โ Single pipe commands
- โ Double pipe commands
- โ Triple pipe commands
- โ External command execution
- โ Error handling
- โ Network communication (Phase 2)
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Follow existing code style
- Add comments for complex logic
- Test your changes thoroughly
- Update documentation as needed
This project is licensed under the MIT License - see the LICENSE file for details.
- Your Name - Initial work - YourGitHub
- Inspired by Unix/Linux shell implementations
- Built as part of Operating Systems coursework
- Thanks to the open-source community
- Phase 2 server handles one client at a time (no concurrent connections)
- No authentication mechanism in Phase 2
- Limited to 3-level pipe depth
- No command history support
- Multi-client support with threading
- Command history and auto-completion
- Configuration file support
- Authentication and encryption (SSL/TLS)
- Job control (background processes)
- Signal handling improvements
- Environment variable support
- Redirection operators (>, >>, <)
Note: This is an educational project. For production use, consider security implications and proper error handling.