{"id":24990030,"url":"https://github.com/rubenhortas/bash_scripting_examples","last_synced_at":"2026-05-11T07:08:23.127Z","repository":{"id":73095065,"uuid":"586988304","full_name":"rubenhortas/bash_scripting_examples","owner":"rubenhortas","description":"Examples of bash scripting","archived":false,"fork":false,"pushed_at":"2025-05-11T16:11:34.000Z","size":40,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-29T06:42:31.776Z","etag":null,"topics":["bash","bash-script","bash-scripting","examples","scripting"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rubenhortas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2023-01-09T17:45:30.000Z","updated_at":"2025-05-11T16:11:37.000Z","dependencies_parsed_at":"2025-05-10T19:26:44.567Z","dependency_job_id":"7d2803eb-b558-4428-b00c-03c977d0a1c0","html_url":"https://github.com/rubenhortas/bash_scripting_examples","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rubenhortas/bash_scripting_examples","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubenhortas%2Fbash_scripting_examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubenhortas%2Fbash_scripting_examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubenhortas%2Fbash_scripting_examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubenhortas%2Fbash_scripting_examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rubenhortas","download_url":"https://codeload.github.com/rubenhortas/bash_scripting_examples/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubenhortas%2Fbash_scripting_examples/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273973979,"owners_count":25200579,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-06T02:00:13.247Z","response_time":2576,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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","bash-script","bash-scripting","examples","scripting"],"created_at":"2025-02-04T13:04:29.217Z","updated_at":"2026-05-11T07:08:23.115Z","avatar_url":"https://github.com/rubenhortas.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bash examples\n\nSmall examples of bash scripting.\n\n![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/rubenhortas/bash_scripting_examples)\n![GitHub repo size](https://img.shields.io/github/repo-size/rubenhortas/bash_scripting_examples)\n\n![GitHub](https://img.shields.io/github/license/rubenhortas/bash_scripting_examples)\n\n## :bookmark: Bash scripting naming conventions\n\n| Element                    |Notation              |Example              |Notes                                                                                                                    |\n|----------------------------|----------------------|---------------------|-------------------------------------------------------------------------------------------------------------------------|\n| Constants                  | SCREAMING_SNAKE_CASE | DEST_PATH           | Use `readonly` or `declare -r` to ensure they are readonly.                                                             |\n| Environment variable names | SCREAMING_SNAKE_CASE | PATH                |                                                                                                                         |\n| File                       | snake_case           | my_script           | Executables should not have extension (strongly preferred) or a `.sh` extension.[^1]                                    |\n| Functions                  | snake_case           | my_function(){ }    | The keyword `function` it's optional, but must be used consistently troughout a project.[^2]                            |\n| Hashbang                   |                      | #!/usr/bin/env bash | #!/usr/bin/bash asumes it's always installed in /bin, which can cause issues.[^3]                                       |\n| Local variables            | snake_case           | my_local_variable   | Ensure that local variables are only seen inside a function and it's children by using `local` when declaring them.     |\n| Variables                  | snake_case           | my_variable         |                                                                                                                         |\n\n## Multiline comments\n\n```bash\n: '\n   line1\n   line2\n'\n```\n\n## :bug: Debug\n\n### Executing\n\n```bash\nbash -x ./script\n```\n\n### With hashbang\n\n```bash\n#/usr/bin/env bash -x\n```\n\n### Debug a block\n\n```bash\nset -x\n\necho \"Code block\"\n\nset +x\n```\n\n## :telephone_receiver: Command calls\n\n### Check  return values\n\nAlways check return values and give informative return values.\nFor unpiped commands use `$?` or check directly via an `if` statement.\n\n```shell\nif ! mv \"${file_list[@]}\" \"${dest_dir}/\"; then\n  echo \"Unable to move ${file_list[*]} to ${dest_dir}\" \u003e\u00262\n  exit 1\nfi\n\n# Or\nmv \"${file_list[@]}\" \"${dest_dir}/\"\nif (( $? != 0 )); then\n  echo \"Unable to move ${file_list[*]} to ${dest_dir}\" \u003e\u00262\n  exit 1\nfi\n```\n\n### Builtin Commands vs External Commands\n\nGiven the choice between invoking a shell builtin and invoking a separete process, choose the builtin.\n\n```shell\n# Prefer this:\naddition=$(( X + Y ))\nsubstitution=\"${string/#foo/bar}\"\n\n# Instead of this:\naddition=\"$(expr \"${X}\" + \"${Y}\")\"\nsubstitution=\"$(echo \"${string}\" | sed -e 's/^foo/bar/')\"\n```\n\n## :mag_right: Static analysis\n\nUse [ShellCheck](https://github.com/koalaman/shellcheck) to get warnings and suggestions for your scripts.\n\n## :books: Sources\n\n* [Google Shell Style Guide](https://google.github.io/styleguide/shellguide.html)\n\n[^1]: Libraries must have a `.sh`extension and should not be executable.\n[^2]: The use of the keyword `function`reduces compatibility with older versions of bash.\n[^3]: Google does recommend `#!/bin/bash`\n\n## :star: Support\n\nIf you find these examples useful, please, consider starring this repository!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubenhortas%2Fbash_scripting_examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frubenhortas%2Fbash_scripting_examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubenhortas%2Fbash_scripting_examples/lists"}