{"id":15042356,"url":"https://github.com/yegor256/qbash","last_synced_at":"2026-02-02T07:54:53.759Z","repository":{"id":257292375,"uuid":"857830280","full_name":"yegor256/qbash","owner":"yegor256","description":"Simple executor of a bash commands from Ruby: it logs the output and checks the exit code","archived":false,"fork":false,"pushed_at":"2025-12-27T03:18:26.000Z","size":320,"stargazers_count":4,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-12-28T21:55:29.272Z","etag":null,"topics":["bash","console","ruby","ruby-gem","terminal"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/qbash","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yegor256.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2024-09-15T18:05:20.000Z","updated_at":"2025-12-27T03:17:19.000Z","dependencies_parsed_at":"2024-09-17T08:11:24.992Z","dependency_job_id":"4d12cf2d-7b66-45b0-adf4-11de5006c36e","html_url":"https://github.com/yegor256/qbash","commit_stats":null,"previous_names":["yegor256/bash","yegor256/qbash"],"tags_count":26,"template":false,"template_full_name":null,"purl":"pkg:github/yegor256/qbash","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yegor256%2Fqbash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yegor256%2Fqbash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yegor256%2Fqbash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yegor256%2Fqbash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yegor256","download_url":"https://codeload.github.com/yegor256/qbash/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yegor256%2Fqbash/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28565001,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-19T08:53:44.001Z","status":"ssl_error","status_checked_at":"2026-01-19T08:52:40.245Z","response_time":67,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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","console","ruby","ruby-gem","terminal"],"created_at":"2024-09-24T20:47:09.786Z","updated_at":"2026-02-02T07:54:53.750Z","avatar_url":"https://github.com/yegor256.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Quick and Simple Executor of Bash Commands\n\n[![DevOps By Rultor.com](https://www.rultor.com/b/yegor256/qbash)](https://www.rultor.com/p/yegor256/qbash)\n[![We recommend RubyMine](https://www.elegantobjects.org/rubymine.svg)](https://www.jetbrains.com/ruby/)\n\n[![rake](https://github.com/yegor256/qbash/actions/workflows/rake.yml/badge.svg)](https://github.com/yegor256/qbash/actions/workflows/rake.yml)\n[![PDD status](https://www.0pdd.com/svg?name=yegor256/qbash)](https://www.0pdd.com/p?name=yegor256/qbash)\n[![Gem Version](https://badge.fury.io/rb/qbash.svg)](https://badge.fury.io/rb/qbash)\n[![Test Coverage](https://img.shields.io/codecov/c/github/yegor256/qbash.svg)](https://codecov.io/github/yegor256/qbash?branch=master)\n[![Yard Docs](https://img.shields.io/badge/yard-docs-blue.svg)](https://rubydoc.info/github/yegor256/qbash/master/frames)\n[![Hits-of-Code](https://hitsofcode.com/github/yegor256/qbash)](https://hitsofcode.com/view/github/yegor256/qbash)\n[![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/yegor256/qbash/blob/master/LICENSE.txt)\n\nHow do you execute a new shell command from Ruby?\nThere are [many ways][so-question].\nNone of them offers a one-liner that would execute a command,\n  print its output to the console or a logger, and then raise an exception if\n  the exit code is not zero.\nThis small gem offers exactly this one-liner.\n\nFirst, install it:\n\n```bash\ngem install qbash\n```\n\nThen, you can use [qbash] global function:\n\n```ruby\nrequire 'qbash'\nstdout = qbash('echo \"Hello, world!\"')\n```\n\nIf the command fails, an exception is raised.\n\nBy default, `stderr` merges with the `stdout` logger.\nYou can redirect it elsewhere:\n\n```ruby\n# Redirect stderr to a separate logger\nout = Loog::Buffer.new\nerr = Loog::Buffer.new\nqbash('cmd', stdout: out, stderr: err)\n\n# Discard stderr completely\nqbash('cmd', stderr: nil)\n```\n\nIt's possible to provide the standard input and environment variables:\n\n```ruby\nstdout = qbash('cat \u003e $FILE', env: { 'FILE' =\u003e 'a.txt' }, stdin: 'Hello!')\n```\n\nIt's possible to configure the logging facility too, for example,\n  with the help of the [loog] gem\n  (the output is returned _and_ printed to the logger):\n\n```ruby\nrequire 'loog'\nqbash('echo \"Hello, world!\"', stdout: Loog::VERBOSE)\n```\n\nYou can also make it return both stdout and exit code,\n  with the help of the `both` option set to `true`:\n\n```ruby\nstdout, code = qbash('cat a.txt', both: true, accept: [])\n```\n\nHere, the `accept` param contains the list of exit codes that are \"acceptable\"\n  and won't lead to runtime failures.\nWhen the list is empty, all exits are acceptable (no failures occur).\n\nThe command may be provided as an array, which is automatically\n  converted to a string by joining all items with spaces between them.\n\n```ruby\nqbash(\n  [\n    'echo \"Hello, world!\"',\n    '\u0026\u0026 echo \"How are you?\"',\n    '\u0026\u0026 cat /etc/passwd'\n  ]\n)\n```\n\nEven simpler:\n\n```ruby\nqbash(\n  'echo \"Hello, world!\"',\n  '\u0026\u0026 echo \"How are you?\"',\n  '\u0026\u0026 cat /etc/passwd'\n)\n```\n\nIf a block is given to `qbash`, it runs the command in background mode,\n  waiting for the block to finish.\nOnce finished, the command is terminated via the `TERM` [signal]:\n\n```ruby\nqbash('sleep 9999') do |pid|\n  # do something\nend\n```\n\nIt is very much recommended to escape all command-line values with the help\n  of the [Shellwords.escape()][shellwords] utility method, for example:\n\n```ruby\nfile = '/tmp/test.txt'\nqbash(\"cat #{Shellwords.escape(file)}\")\n```\n\nWithout such escaping, a space inside the `file` variable\n  leads to an unpredictable result.\n\nIf you want to stop sooner than the command finishes, use [timeout] gem:\n\n```ruby\nrequire 'timeout'\nTimeout.timeout(5) do\n  qbash('sleep 100')\nend\n```\n\nThis raises a `Timeout::Error` exception after five seconds\n  of waiting for `sleep` to finish.\n\n## How to contribute\n\nRead [these guidelines][guidelines].\nMake sure your build is green before you contribute your pull request.\nYou need [Ruby] 3.0+ and [Bundler] installed.\nThen:\n\n```bash\nbundle update\nbundle exec rake\n```\n\nIf it's clean and you don't see any error messages, submit your pull request.\n\n[Bundler]: https://bundler.io/\n[guidelines]: https://www.yegor256.com/2014/04/15/github-guidelines.html\n[loog]: https://github.com/yegor256/loog\n[qbash]: https://rubydoc.info/github/yegor256/qbash/master/Kernel#qbash-instance_method\n[Ruby]: https://www.ruby-lang.org/en/\n[shellwords]: https://ruby-doc.org/stdlib-3.0.1/libdoc/shellwords/rdoc/Shellwords.html\n[signal]: https://en.wikipedia.org/wiki/Signal_(IPC)\n[so-question]: https://stackoverflow.com/questions/2232/\n[timeout]: https://github.com/ruby/timeout\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyegor256%2Fqbash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyegor256%2Fqbash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyegor256%2Fqbash/lists"}