{"id":29153303,"url":"https://github.com/supernova106/bash-firefighter","last_synced_at":"2026-05-04T23:32:19.222Z","repository":{"id":44877850,"uuid":"248822907","full_name":"supernova106/bash-firefighter","owner":"supernova106","description":"Curated list of useful bash techniques","archived":false,"fork":false,"pushed_at":"2022-05-11T06:13:49.000Z","size":64,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-01T01:05:34.209Z","etag":null,"topics":["bash","yaml","yaml-parser"],"latest_commit_sha":null,"homepage":null,"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/supernova106.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}},"created_at":"2020-03-20T18:14:03.000Z","updated_at":"2022-12-14T06:25:19.000Z","dependencies_parsed_at":"2022-09-10T19:11:23.828Z","dependency_job_id":null,"html_url":"https://github.com/supernova106/bash-firefighter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/supernova106/bash-firefighter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supernova106%2Fbash-firefighter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supernova106%2Fbash-firefighter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supernova106%2Fbash-firefighter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supernova106%2Fbash-firefighter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/supernova106","download_url":"https://codeload.github.com/supernova106/bash-firefighter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supernova106%2Fbash-firefighter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32628803,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-04T10:08:07.713Z","status":"ssl_error","status_checked_at":"2026-05-04T10:08:02.005Z","response_time":58,"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","yaml","yaml-parser"],"created_at":"2025-07-01T01:05:28.830Z","updated_at":"2026-05-04T23:32:19.195Z","avatar_url":"https://github.com/supernova106.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bash-firefighter\n\nCurated list of useful bash techniques\n\n## Table of Contents\n\n- [Helper](#user-content-helper)\n- [Generic](#user-content-generic)\n- [Programming](#user-content-programming)\n  - [Array](#user-content-array)\n  - [Join](#user-content-join-method)\n  - [Variables](#user-content-variables)\n  - [Split](#user-content-split-method)\n  - [Regex](#user-content-regex)\n  - [Modules](#user-content-modules)\n  - [Function in Function](#user-content-function-in-function)\n- [Config Files](#user-content-config-files)\n  - [Convert YAML to key=value](#user-content-yaml)\n- [Cloud Provider](#user-content-cloud-provider)\n  - [AWS](#user-content-aws)\n\n## \u003ca name=\"user-content-helper\"\u003e\u003c/a\u003eHelper\n\n- yq, refer to [install_yq.sh](./scripts/install_yq.sh). Or [other ways](https://mikefarah.gitbook.io/yq/#on-ubuntu-16-04-or-higher-from-debian-package)\n- jq, refer to [install_jq.sh](./scripts/install_jq.sh)\n- Get local directory of script [local_dir.sh](./scripts/local_dir.sh)\n- Get OS platform [get_os.sh](./scripts/get_os.sh)\n- Promote AWS ECR Image [promote_ecr.sh](./scripts/promote_ecr.sh)\n\n## \u003ca name=\"user-content-generic\"\u003e\u003c/a\u003eGeneric\n\n### Check if a port is open\n\n```sh\nif [ \"$(timeout 1 bash -c '\u003c/dev/tcp/localhost/9100'; echo $?)\" == \"0\" ]; then\n        echo \"hi\"\nfi\n```\n\n### get OS Platform\n\n```sh\nOS_PLATFORM=$(cat /etc/os-release | awk -F= '/^ID=/{print $2}' | tr -d '\"')\necho $OS_PLATFORM\n```\n\n### \u003ca name=\"user-content-exit-on-error\"\u003e\u003c/a\u003eExit on error\n\n```sh\n#!/bin/bash\nset -e\n```\n\n### \u003ca name=\"user-content-retry-on-error\"\u003e\u003c/a\u003eRetry on error\n\n- Refer to [retry.sh](./scripts/retry.sh)\n\n### \u003ca name=\"user-content-user-continue\"\u003e\u003c/a\u003eUser Continue\n\n- Refer to [user_continue.sh](./scripts/user_continue.sh)\n\n## \u003ca name=\"user-content-programming\"\u003e\u003c/a\u003eProgramming\n\n### \u003ca name=\"user-content-array\"\u003e\u003c/a\u003eArray\n\nLoop through indices, values\n\n```sh\nfor i in \"${!foo[@]}\"; do\n  echo \"${i}: ${foo[$i]}\"\ndone\n```\n\nLoop through values\n\n```sh\nfor i in \"${foo[@]}\"; do\n  echo \"${i}\"\ndone\n```\n\n### \u003ca name=\"user-content-join-method\"\u003e\u003c/a\u003eJoin method\n\nJoin array to string\n\n```sh\nfoo_arr=['a','b','c']\nbar=$(IFS=. ; echo \"${foo_arr[*]}\")\n\n# a.b.c\n```\n\n### \u003ca name=\"user-content-variables\"\u003e\u003c/a\u003eVariables\n\nDeclare local variable\n\n```sh\nfunction foo() {\n  local bar=\"\"\n}\n\nfoo\n# only work with function\n```\n\nDeclare global variable\n\n```sh\nbar=\"\"\n\nfunction foo() {\n  echo \"${bar}\"\n}\n```\n\nDefault value\n\n```sh\nbar=\"${1:-default}\"\n\necho \"${bar}\"\n# default\n```\n\n### \u003ca name=\"user-content-split-method\"\u003e\u003c/a\u003eSplit method\n\nSplit string to array\n\n```sh\nIFS='.' read -ra arr \u003c\u003c\u003c \"a.b.c\"\n\necho \"${arr[@]}\n# ['a', 'b', 'c']\n```\n\n### \u003ca name=\"user-content-regex\"\u003e\u003c/a\u003eRegex\n\nValidate IP address\n\n```sh\nif [[ ! $ip =~ ^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$ ]]; then\n  echo -e \"error! $ip is not valid\"\n  return 1\nfi\n```\n\n### \u003ca name=\"user-content-function-in-function\"\u003e\u003c/a\u003eFunction in Function\n\n```sh\nfoo() (\n  bar() {\n    echo \"hello\"\n  }\n\n  bar\n)\n```\n\n### \u003ca name=\"user-content-modules\"\u003e\u003c/a\u003eModules\n\ninlude bash file as a module\n\n```sh\n.\n├── foo.sh\n└── modules\n    └── utils.sh\n\n$ cat modules/utils.sh\n#!/bin/bash\n\nfunction bar() {\n  echo \"hello\"\n}\n\n$ cat foo.sh\n#!/bin/bash\n\nsource modules/utils.sh\n\nbar\n\n```\n\n## \u003ca name=\"user-content-config-files\"\u003e\u003c/a\u003eConfig Files\n\n### \u003ca name=\"user-content-yaml\"\u003e\u003c/a\u003eYaml\n\nConvert `yaml` file (work with up to level 2 of keys) to `key=value` environment variables file\n\n- Detect if the input file's content changes with `md5()` hash\n- allow bash to work with yaml for configuration automation\n\nRequirements\n\n- yq\n- jq\n\nRefer to [convert_yaml_to_env.sh](./scripts/convert_yaml_to_env.sh)\n\n## \u003ca name=\"user-content-cloud-provider\"\u003e\u003c/a\u003eCloud Provider\n\n### \u003ca name=\"user-content-aws\"\u003e\u003c/a\u003eAWS\n\nGetting VPC CIDR from VPC_ID\n\n```sh\nvpc_id=${1}\naws ec2 describe-vpcs --vpc-ids $vpc_id | jq -r .Vpcs[0].CidrBlock\n```\n\nGetting available ENIs ID\n\n```sh\naws ec2 describe-network-interfaces --region us-west-2 --filters Name=status,Values=available,Name=group-name,Values=\u003cGROUP_NAME\u003e --max-items 2 | jq -r .NetworkInterfaces[].NetworkInterfaceId\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsupernova106%2Fbash-firefighter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsupernova106%2Fbash-firefighter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsupernova106%2Fbash-firefighter/lists"}