{"id":48195270,"url":"https://github.com/lsferreira42/bash-ini-parser","last_synced_at":"2026-04-04T18:02:58.586Z","repository":{"id":285148618,"uuid":"957207577","full_name":"lsferreira42/bash-ini-parser","owner":"lsferreira42","description":"Bash INI Parser Library","archived":false,"fork":false,"pushed_at":"2026-02-16T15:07:05.000Z","size":147,"stargazers_count":43,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2026-02-16T22:45:55.801Z","etag":null,"topics":["bash","ini","ini-parser","shell-script","shell-scripting"],"latest_commit_sha":null,"homepage":"https://lsferreira42.github.io/bash-ini-parser/","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lsferreira42.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-03-29T20:05:08.000Z","updated_at":"2026-02-16T15:07:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"1743e2dd-024c-48ab-8fcb-620d24fc089f","html_url":"https://github.com/lsferreira42/bash-ini-parser","commit_stats":null,"previous_names":["lsferreira42/bash-ini-parser"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/lsferreira42/bash-ini-parser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lsferreira42%2Fbash-ini-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lsferreira42%2Fbash-ini-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lsferreira42%2Fbash-ini-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lsferreira42%2Fbash-ini-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lsferreira42","download_url":"https://codeload.github.com/lsferreira42/bash-ini-parser/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lsferreira42%2Fbash-ini-parser/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31407654,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-04T10:20:44.708Z","status":"ssl_error","status_checked_at":"2026-04-04T10:20:06.846Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","ini","ini-parser","shell-script","shell-scripting"],"created_at":"2026-04-04T18:02:17.239Z","updated_at":"2026-04-04T18:02:58.567Z","avatar_url":"https://github.com/lsferreira42.png","language":"Shell","readme":"# Bash INI Parser\n\n![Build](https://github.com/lsferreira42/bash-ini-parser/actions/workflows/ci.yml/badge.svg)\n![License](https://img.shields.io/github/license/lsferreira42/bash-ini-parser.svg)\n![Last Commit](https://img.shields.io/github/last-commit/lsferreira42/bash-ini-parser.svg)\n![Stars](https://img.shields.io/github/stars/lsferreira42/bash-ini-parser.svg)\n![Issues](https://img.shields.io/github/issues/lsferreira42/bash-ini-parser.svg)\n\nA robust shell script library for parsing and manipulating INI configuration files in Bash.\n\n## Features\n\n- **Read and write** values from/to INI files\n- **List sections and keys** in INI files\n- **Add, update, and remove** sections and keys\n- **Rename sections and keys** with validation\n- **Validate INI file structure** for correctness\n- **Format and organize** INI files with indentation and sorting\n- **Batch operations** for efficient bulk updates\n- **Merge files** with configurable conflict resolution strategies\n- **Export to JSON and YAML** formats\n- **Supports complex values** including quotes, spaces, and special characters\n- **Array support** for storing multiple values\n- **Import/export functionality** between files and environment variables\n- **Extensive error handling** with detailed error messages\n- **Debug mode** for troubleshooting\n- **Configurable behavior** through environment variables\n- **Security features** including path validation, file locking, and atomic operations\n- **Backwards compatible** with previous versions\n\n## Installation\n\nSimply include the `lib_ini.sh` script in your project and source it in your shell scripts:\n\n```bash\nsource /path/to/lib_ini.sh\n```\n\n## Basic Usage\n\n```bash\n#!/bin/bash\nsource ./lib_ini.sh\n\n# Create a new INI file with sections and keys\nCONFIG_FILE=\"config.ini\"\nini_add_section \"$CONFIG_FILE\" \"app\"\nini_write \"$CONFIG_FILE\" \"app\" \"name\" \"My Application\"\nini_write \"$CONFIG_FILE\" \"app\" \"version\" \"1.0.0\"\n\n# Read values\napp_name=$(ini_read \"$CONFIG_FILE\" \"app\" \"name\")\necho \"App name: $app_name\"\n\n# List sections and keys\necho \"Available sections:\"\nini_list_sections \"$CONFIG_FILE\" | while read section; do\n    echo \"- $section\"\n    echo \"  Keys:\"\n    ini_list_keys \"$CONFIG_FILE\" \"$section\" | while read key; do\n        value=$(ini_read \"$CONFIG_FILE\" \"$section\" \"$key\")\n        echo \"  - $key = $value\"\n    done\ndone\n\n# Remove a key\nini_remove_key \"$CONFIG_FILE\" \"app\" \"name\"\n\n# Remove a section\nini_remove_section \"$CONFIG_FILE\" \"app\"\n```\n\n## Advanced Features\n\n### Array Support\n\n```bash\n# Write array values\nini_write_array \"$CONFIG_FILE\" \"app\" \"supported_formats\" \"jpg\" \"png\" \"gif\"\n\n# Read array values\nformats=$(ini_read_array \"$CONFIG_FILE\" \"app\" \"supported_formats\")\nfor format in $formats; do\n    echo \"Format: $format\"\ndone\n```\n\n### Default Values\n\n```bash\n# Get a value or use a default if not found\ntimeout=$(ini_get_or_default \"$CONFIG_FILE\" \"app\" \"timeout\" \"30\")\n```\n\n### Environment Variables Export\n\n```bash\n# Export all INI values to environment variables with a prefix\nini_to_env \"$CONFIG_FILE\" \"CFG\"\necho \"App name from env: $CFG_app_name\"\n\n# Export only one section\nini_to_env \"$CONFIG_FILE\" \"CFG\" \"database\"\n```\n\n### File Import\n\n```bash\n# Import all values from one INI file to another\nini_import \"defaults.ini\" \"config.ini\"\n\n# Import only specific sections\nini_import \"defaults.ini\" \"config.ini\" \"section1\" \"section2\"\n```\n\n### Key Existence Check\n\n```bash\nif ini_key_exists \"config.ini\" \"app\" \"version\"; then\n    echo \"The key exists\"\nfi\n```\n\n### File Validation\n\n```bash\n# Validate the structure of an INI file\nif ini_validate \"config.ini\"; then\n    echo \"File is valid\"\nelse\n    echo \"File has errors\"\nfi\n```\n\n### Get All Keys from a Section\n\n```bash\n# Get all key=value pairs from a section at once\nini_get_all \"config.ini\" \"app\"\n# Output:\n# name=My Application\n# version=1.0.0\n# debug=true\n```\n\n### Rename Sections and Keys\n\n```bash\n# Rename a section\nini_rename_section \"config.ini\" \"old_section\" \"new_section\"\n\n# Rename a key within a section\nini_rename_key \"config.ini\" \"app\" \"old_key\" \"new_key\"\n```\n\n### Format INI Files\n\n```bash\n# Format file with indentation and sorted keys\nini_format \"config.ini\" 2 1\n# Parameters: file, indent_spaces, sort_keys (0=no, 1=yes)\n\n# Basic formatting (no indentation, no sorting)\nini_format \"config.ini\"\n```\n\n### Batch Write Operations\n\n```bash\n# Write multiple key-value pairs at once\nini_batch_write \"config.ini\" \"app\" \\\n    \"name=MyApp\" \\\n    \"version=1.0\" \\\n    \"debug=true\" \\\n    \"timeout=30\"\n```\n\n### Merge INI Files\n\n```bash\n# Merge source.ini into target.ini with overwrite strategy\nini_merge \"source.ini\" \"target.ini\" \"overwrite\"\n\n# Available strategies:\n# - \"overwrite\": Replace existing values with source values\n# - \"skip\": Keep existing values, only add new keys\n# - \"merge\": Append source values to existing values (comma-separated)\n\n# Merge only specific sections\nini_merge \"source.ini\" \"target.ini\" \"overwrite\" \"section1\" \"section2\"\n```\n\n### Export to JSON and YAML\n\n```bash\n# Export to JSON (compact format)\nini_to_json \"config.ini\" 0\n\n# Export to JSON (pretty format with indentation)\nini_to_json \"config.ini\" 1\n\n# Export to YAML (default 2-space indent)\nini_to_yaml \"config.ini\"\n\n# Export to YAML (custom indent)\nini_to_yaml \"config.ini\" 4\n```\n\n## Configuration Options\n\nThe library's behavior can be customized by setting these variables either directly in your script after sourcing the library or as environment variables before sourcing the library:\n\n```bash\n# Method 1: Set in your script after sourcing\nsource ./lib_ini.sh\nINI_DEBUG=1\n\n# Method 2: Set as environment variables before sourcing\nexport INI_DEBUG=1\nsource ./lib_ini.sh\n```\n\nAvailable configuration options:\n\n```bash\n# Enable debug mode to see detailed operations\nINI_DEBUG=1\n\n# Enable strict validation of section and key names\nINI_STRICT=1\n\n# Allow empty values\nINI_ALLOW_EMPTY_VALUES=1\n\n# Allow spaces in section and key names\nINI_ALLOW_SPACES_IN_NAMES=1\n```\n\n## Library Enhancements\n\n### Security Improvements\n\n- **Input validation** for all parameters\n- **Path traversal protection** to prevent directory traversal attacks\n- **Secure regex handling** with proper escaping of special characters\n- **Temporary file security** with automatic cleanup and tracking\n- **File permission checks** to ensure proper access rights\n- **File locking** to prevent race conditions during concurrent writes\n- **Atomic operations** with backup creation for data integrity\n- **Symlink resolution** to prevent malicious symlink attacks\n- **File size validation** to prevent resource exhaustion\n- **Environment variable name sanitization** for safe export\n- **Automatic directory creation** when needed\n\n### Core Function Enhancements\n\n#### File Operations\n- `ini_check_file` automatically creates directories and verifies permissions\n- Atomic write operations to prevent file corruption during updates\n\n#### Reading and Writing\n- Support for quoted values and special characters\n- Better handling of complex strings\n- Robust error detection and reporting\n\n#### Utility Functions\n- `ini_debug` - Displays debug messages when debug mode is enabled\n- `ini_error` - Standardized error message format\n- `ini_validate_section_name` and `ini_validate_key_name` - Validate input data\n- `ini_validate_path` - Validates file paths and prevents traversal attacks\n- `ini_resolve_symlink` - Safely resolves symbolic links\n- `ini_check_file_size` - Validates file size limits\n- `ini_validate_env_var_name` - Validates environment variable names\n- `ini_lock_file` and `ini_unlock_file` - File locking for concurrent access\n- `ini_create_temp_file` - Creates temporary files securely\n- `ini_trim` - Removes whitespace from strings\n- `ini_escape_for_regex` - Properly escapes special characters\n\n#### Advanced Functions\n- `ini_validate` - Validates complete INI file structure\n- `ini_get_all` - Retrieves all key-value pairs from a section\n- `ini_rename_section` - Renames a section in the file\n- `ini_rename_key` - Renames a key within a section\n- `ini_format` - Formats and organizes INI files\n- `ini_batch_write` - Writes multiple key-value pairs efficiently\n- `ini_merge` - Merges INI files with configurable strategies\n- `ini_to_json` - Exports INI file to JSON format\n- `ini_to_yaml` - Exports INI file to YAML format\n\n### Advanced Usage Examples\n\n#### Working with Multiple Files\n\n```bash\n# Import default settings, then override with user settings\nini_import \"defaults.ini\" \"config.ini\"\nini_import \"user_prefs.ini\" \"config.ini\"\n\n# Copy specific sections between files\nini_import \"source.ini\" \"target.ini\" \"section1\" \"section2\"\n```\n\n#### Integration with Database Scripts\n\n```bash\n# Load database configuration into environment variables\nini_to_env \"database.ini\" \"DB\"\n\n# Use in database commands\nmysql -h \"$DB_mysql_host\" -u \"$DB_mysql_user\" -p\"$DB_mysql_password\" \"$DB_mysql_database\"\n```\n\n#### Array Manipulation\n\n```bash\n# Store a list of roles in an array\nini_write_array \"config.ini\" \"permissions\" \"roles\" \"admin\" \"user\" \"guest\"\n\n# Read and process array values\nroles=$(ini_read_array \"config.ini\" \"permissions\" \"roles\")\nfor role in $roles; do\n    echo \"Processing role: $role\"\n    # Additional processing...\ndone\n```\n\n## Examples\n\nCheck the `examples` directory for complete usage examples:\n\n- `basic_usage.sh`: Demonstrates core functionality\n- `advanced_usage.sh`: Shows advanced features\n\n## Testing\n\nRun the comprehensive test suite:\n\n```bash\nmake test\n```\n\nThe test suite includes:\n- **Basic tests** (47 tests): Core functionality validation\n- **Extended tests** (24 tests): Advanced features like arrays and imports\n- **Environment override tests** (11 tests): Configuration option validation\n- **Security tests** (25 tests): Security and durability improvements\n- **Advanced features tests** (39 tests): New advanced features validation\n\n**Total: 146 tests** covering all library functionality.\n\n## License\n\nThis project is licensed under the BSD License, a permissive free software license with minimal restrictions on the use and distribution of covered software.\n\n## Author\n\n- **Leandro Ferreira**\n- Website: [leandrosf.com](https://leandrosf.com)\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request. ","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flsferreira42%2Fbash-ini-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flsferreira42%2Fbash-ini-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flsferreira42%2Fbash-ini-parser/lists"}