{"id":21480890,"url":"https://github.com/essentialkaos/knf-bash","last_synced_at":"2026-04-24T21:33:38.556Z","repository":{"id":144786705,"uuid":"409374244","full_name":"essentialkaos/knf-bash","owner":"essentialkaos","description":"Parser for KNF files for use in bash scripts","archived":false,"fork":false,"pushed_at":"2021-09-22T22:30:52.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-06-05T15:05:25.520Z","etag":null,"topics":["bash","knf"],"latest_commit_sha":null,"homepage":"https://kaos.sh/knf-bash","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/essentialkaos.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":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-09-22T22:30:03.000Z","updated_at":"2021-09-22T22:31:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"f90b6467-8597-44f0-8d6f-a6a291ea0111","html_url":"https://github.com/essentialkaos/knf-bash","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/essentialkaos/knf-bash","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/essentialkaos%2Fknf-bash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/essentialkaos%2Fknf-bash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/essentialkaos%2Fknf-bash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/essentialkaos%2Fknf-bash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/essentialkaos","download_url":"https://codeload.github.com/essentialkaos/knf-bash/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/essentialkaos%2Fknf-bash/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32241794,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-24T13:21:15.438Z","status":"ssl_error","status_checked_at":"2026-04-24T13:21:15.005Z","response_time":64,"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","knf"],"created_at":"2024-11-23T12:18:57.401Z","updated_at":"2026-04-24T21:33:38.543Z","avatar_url":"https://github.com/essentialkaos.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003ca href=\"#readme\"\u003e\u003cimg src=\"https://gh.kaos.st/knf-bash.svg\"/\u003e\u003c/a\u003e\u003c/p\u003e\n\n\u003cbr/\u003e\n\nThis repository contains a parser for [KNF files](https://kaos.sh/knf-spec) for use in bash scripts.\n\nAll properties from the KNF file after parsing will be defined as global variables with the next naming scheme: `section_property`. For example, property from section \"http\" with the name \"ip\" will be defined as variable `http_ip`.\n\nIf the property name contains one or more `-` symbols, all of them will be replaced by the symbol `_`. For example, property from section \"http\" with the name \"port-range\" will be defined as variable `http_port_range`.\n\nAll uppercase symbols will be transformed to lowercase. For example, property from section \"HTTP\" with the name \"Port\" will be defined as variable `http_port`.\n\n### Usage example\n\n```\n[log]\n\n  # Path to directory with logs\n  dir: /var/log/myapp\n\n  # Path to log file\n  file: {log:dir}/myapp.log\n```\n\n```bash\n#!/bin/bash\n\nmain() {\n  local config=\"~/config.knf\"\n\n  if [[ -d \"$log_dir\" ]] ; then\n    echo \"Text for log\" \u003e\u003e $log_file\n  fi\n}\n\nparseKNF() {\n  local knf=\"${1//\\~/$HOME}\"\n  local knf_app knf_line knf_sec knf_prop knf_val knf_macro\n\n  if [[ ! -r \"$knf\" ]] ; then\n    echo \"File $knf is not exist or not readable\" 1\u003e\u00262\n    return 1\n  fi\n\n  for knf_app in \"echo\" \"cut\" \"sed\" \"tr\" \"grep\" ; do\n    if ! type -P \"$knf_app\" \u0026\u003e /dev/null ; then\n      echo \"KNF parsing requires $knf_app utility\" 1\u003e\u00262\n      return 1\n    fi\n  done\n\n  while read knf_line ; do\n    if [[ $knf_line =~ \\[([a-zA-Z0-9_-]+)\\] ]] ; then\n      knf_sec=\"${BASH_REMATCH[1]}\"\n      continue\n    fi\n\n    if [[ $knf_line =~ ^[\\ \\t]*([a-zA-Z0-9_-]+): ]] ; then\n      knf_prop=\"${BASH_REMATCH[1]//-/_}\"\n    else\n      echo \"File $knf is misformatted\" 1\u003e\u00262\n      return 1\n    fi\n\n    knf_prop=$(echo \"$knf_prop\" | tr '[:upper:]' '[:lower:]')\n    knf_val=$(echo \"$knf_line\" | cut -f2-99 -d':' | sed 's/^ *//g' | sed 's/^\\t*//g' | sed 's/ *$//g')\n\n    if [[ -z \"$knf_val\" || \"$knf_val\" == \"false\" ]] ; then\n      continue\n    fi\n\n    while : ; do\n      if [[ \"$knf_val\" =~ \\{([a-zA-Z0-9_-]+:[a-zA-Z0-9_-]+)\\} ]] ; then\n        knf_macro=\"${BASH_REMATCH[1]/:/_}\"\n        knf_val=\"${knf_val//${BASH_REMATCH[0]}/${!knf_macro}}\"\n      else\n        break\n      fi\n    done\n\n    declare -g \"${knf_sec}_${knf_prop}\"=\"$knf_val\"\n\n  done \u003c \u003c(grep -Pv '^[ ]*(#(?!\\!)|[ ]*$)|false[ ]*$' \"$knf\")\n}\n\nmain \"$@\"\n```\n\n### Contributing\n\nBefore contributing to this project please read our [Contributing Guidelines](https://github.com/essentialkaos/contributing-guidelines#contributing-guidelines).\n\n### License\n\n[Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0)\n\n\u003cp align=\"center\"\u003e\u003ca href=\"https://essentialkaos.com\"\u003e\u003cimg src=\"https://gh.kaos.st/ekgh.svg\"/\u003e\u003c/a\u003e\u003c/p\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fessentialkaos%2Fknf-bash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fessentialkaos%2Fknf-bash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fessentialkaos%2Fknf-bash/lists"}