A lightweight, file-based database management system built entirely in Bash. This project provides a command-line interface for creating and managing databases and tables with full CRUD operations, data validation, and CSV export capabilities.
- Features
- Installation
- Quick Start
- Project Structure
- Supported Data Types
- Data Validations
- Usage Examples
- Security Features
- Technical Details
- Requirements
- Limitations
- Future Enhancements
- Contributing
- License
- β Create Database - Create new databases with validation
- π List Databases - View all available databases
- π Connect to Database - Switch context to work with a specific database
- ποΈ Delete Database - Remove databases with confirmation prompts
- β Create Table - Define tables with custom columns and data types
- π List Tables - Display all tables in the current database
- β Drop Table - Delete tables with confirmation
- π₯ Insert Row - Add new records with data validation
- π Select Data - Query and display table data (all columns or specific columns)
- ποΈ Delete Row - Remove records by primary key
- βοΈ Update Cell - Modify specific cell values
- π€ Export to CSV - Export table data to CSV format
- Clone the repository:
git clone https://github.com/yourusername/bash-dbms.git
cd bash-dbms- Make the scripts executable:
chmod +x db.sh table.sh- Run the main script:
./db.shHere's a quick example to get you started:
# Start the DBMS
./db.sh
# Create a database
Select option: 1
Enter Database Name: test_db
# Connect to the database
Select option: 3
Enter Database Name: test_db
# Create a table
Choose option: 1
Enter table name: employees
Number of columns: 3
# Follow the prompts to create your table
# Insert some data
Choose option: 4
# Follow the prompts to insert data
# View your data
Choose option: 5
# Select all columns or specific onesbash-dbms/
βββ db.sh # Main database management interface
βββ table.sh # Table operations and data management
βββ data/ # Directory where databases are stored (auto-created)
β βββ [dbname]/ # Individual database directories
β βββ *.meta # Table metadata files
β βββ *.data # Table data files
βββ README.md # Project documentation
| Type | Description | Example |
|---|---|---|
| π’ Int | Positive integers only | 42, 1000 |
| π String | Text data (max 30 chars, no :) |
john_doe, Hello World |
| π£ Float | Decimal numbers | 3.14, 99.99 |
| π Date | Date in YYYY-MM-DD format | 2025-01-04 |
The system includes comprehensive validation rules to ensure data integrity:
| Rule | Description |
|---|---|
| β Non-empty | Database name cannot be blank |
| π Length | Must be between 3 and 20 characters |
| π€ Format | Must start with a letter, followed by letters, numbers, or underscores only |
| π Uniqueness | Database name must not already exist |
| π‘οΈ Path Safety | Prevents path traversal attacks by sanitizing input |
| Rule | Description |
|---|---|
| β Non-empty | Table name cannot be blank |
| π€ Format | Must start with a letter, contain only alphanumeric characters and underscores |
| π« Reserved Keywords | Cannot use SQL keywords (SELECT, FROM, WHERE, INSERT, UPDATE, DELETE, TABLE, CREATE, DROP) |
| π Uniqueness | Table name must not already exist in the database |
| Rule | Description |
|---|---|
| π Unique Names | Column names must be unique within a table |
| π€ Format Rules | Same naming conventions as tables |
| π« Reserved Keywords | Cannot use SQL reserved keywords |
| π Primary Key | First column is automatically set as primary key (PK) |
- Must match pattern:
^[0-9]+$ - Only positive integers allowed
- Example:
123,456789
- Must match pattern:
^[0-9]+([.][0-9]+)?$ - Decimal point optional
- Example:
3.14,100,99.99
- Maximum 30 characters
- Cannot contain
:character (used as field delimiter) - Leading and trailing spaces are automatically trimmed
- Example:
john_doe,Product Name
- Must match
YYYY-MM-DDformat - Must be a valid calendar date (verified using system date validation)
- Example:
2025-01-04,1990-12-31
| Rule | Description |
|---|---|
| β Non-empty | PK value cannot be blank |
| π Uniqueness | PK values must be unique across all rows |
| β Type Compliance | Must match the datatype defined for the PK column |
- βοΈ Whitespace Removal - Leading and trailing spaces are automatically removed
- β Empty Check - All inputs are validated for non-empty values
- π« Special Characters - Field delimiter (
:) is prohibited in string values - π Case Handling - Reserved keywords are checked case-insensitively
Select option: 1
Enter Database Name: myapp_db
β
Success: Database 'myapp_db' created successfully!Choose option: 1
Enter table name: users
Number of columns: 3
Column 1 name: id
Datatype (Int/String/Float/Date): Int
Column 2 name: username
Datatype (Int/String/Float/Date): String
Column 3 name: created_at
Datatype (Int/String/Float/Date): Date
β
Table 'users' created successfully!Choose option: 4
Table name: users
Enter id (Int): 1
Enter username (String): john_doe
Enter created_at (Date): 2025-01-04
β
Row inserted successfully!Choose option: 5
Enter table name: users
Available columns:
1) id
2) username
3) created_at
Select columns (* for all or e.g. 1,3): *
# Output:
id username created_at
1 john_doe 2025-01-04Choose option: 7
Enter table name: users
Enter PK value: 1
Enter Column number: 2
Enter New value: jane_doe
β
Value updated successfully.Choose option: 6
Enter table name: users
Enter PK value to delete: 1
β
Row with PK '1' deleted successfully.Choose option: 8
Enter table name to export: users
β
Table 'users' exported to 'users.csv' successfully!- π Permission Control - Database directories are created with
700permissions - π‘οΈ Path Traversal Prevention - Input sanitization prevents directory traversal attacks
β οΈ Confirmation Prompts - Destructive operations require explicit confirmation- βοΈ Script Validation - Checks for required files before execution
Metadata Files (.meta)
column_name:datatype:PK
column_name:datatype
Data Files (.data)
value1:value2:value3
value1:value2:value3
- π΄ Red - Errors and warnings
- π’ Green - Success messages
- π‘ Yellow - Warnings and prompts
- π΅ Blue - Headers and informational text
- Bash 4.0 or higher
- Standard Unix utilities:
awk,sed,grep,cut,paste,column,date - Linux or Unix-like operating system
- βοΈ Single-user system (no concurrent access handling)
- π No transaction support
- π No indexing (linear search for all operations)
- πΎ Limited to local file system storage
- Multi-table JOIN operations
- WHERE clause filtering in SELECT
- Backup and restore functionality
- User authentication and permissions
- Transaction support with rollback
- Indexing for faster lookups
- Support for NULL values
- Import data from CSV
- Foreign key constraints
- Aggregate functions (COUNT, SUM, AVG)
Contributions are welcome! Please feel free to submit a Pull Request.
- π΄ Fork the repository
- π§ Create your 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
This project is open source and available under the MIT License.
Created as an educational project to demonstrate database management concepts using Bash scripting, for ITI Open Source 9-Months Program.
Developed By: Ahmed Rabie & Mokhtar Mohamed
Give a βοΈ if this project helped you!
==========================================
BASH DATABASE MANAGEMENT SYSTEM
==========================================
1) Create Database
2) List Databases
3) Connect to Database
4) Delete Database
5) Exit
1) Create Table
2) List Tables
3) Drop Table
4) Insert Row
5) Select Data
6) Delete Row
7) Update Cell
8) Export To CSV (Bonus)
9) Exit
Made with β€οΈ and Bash