{"id":22569111,"url":"https://github.com/henrikbengtsson/shellcheck-repl","last_synced_at":"2025-04-10T12:36:23.848Z","repository":{"id":146695757,"uuid":"178597622","full_name":"HenrikBengtsson/shellcheck-repl","owner":"HenrikBengtsson","description":"Validation of Shell Commands at the Prompt Before Evaluation","archived":false,"fork":false,"pushed_at":"2024-04-25T21:37:55.000Z","size":158,"stargazers_count":18,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-31T15:24:28.592Z","etag":null,"topics":["bash","repl","shell","shellcheck","validation"],"latest_commit_sha":null,"homepage":"https://github.com/HenrikBengtsson/shellcheck-repl","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HenrikBengtsson.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}},"created_at":"2019-03-30T18:42:13.000Z","updated_at":"2024-12-13T02:23:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"b1de3b66-7e43-4c12-9d9a-fd77aa17b9e6","html_url":"https://github.com/HenrikBengtsson/shellcheck-repl","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HenrikBengtsson%2Fshellcheck-repl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HenrikBengtsson%2Fshellcheck-repl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HenrikBengtsson%2Fshellcheck-repl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HenrikBengtsson%2Fshellcheck-repl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HenrikBengtsson","download_url":"https://codeload.github.com/HenrikBengtsson/shellcheck-repl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248217150,"owners_count":21066633,"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","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","repl","shell","shellcheck","validation"],"created_at":"2024-12-08T00:18:03.833Z","updated_at":"2025-04-10T12:36:23.811Z","avatar_url":"https://github.com/HenrikBengtsson.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![shellcheck](https://github.com/HenrikBengtsson/shellcheck-repl/actions/workflows/shellcheck.yml/badge.svg)](https://github.com/HenrikBengtsson/shellcheck-repl/actions/workflows/shellcheck.yml)\n\n# ShellCheck REPL: Validation of Shell Commands Before Evaluation\n\n[ShellCheck] is a great tool for validating your Unix shell scripts.\nIt will parse the scripts and warn about mistakes, errors, and\npotential problems.  This tool - **shellcheck-repl** - brings\nShellCheck validation to the [Bash] read-eval-print loop (REPL),\ni.e. the [Bash] prompt.  Getting this type of validation and feedback\nat the prompt lowers the risk of damaging mistakes and will help you\nbecome a better Bash user and developer.\n\nThe **shellcheck-repl** tool injects itself into the Bash REPL where\nit intercepts the read command line, validates the content via\nShellCheck, and if it is all OK, then the command is evaluated and\nprinted as usual.  However, if there is a mistake, then the command\nwill _not_ be evaluated and an informative error message is displayed\ninstead.  For example, assume we do:\n\n```sh\n$ words=\"lorem ipsum dolor\"\n$ for w in \"$words\"; do echo $w; done\n```\n\nAlthough this looks like a simple for loop, it might not be clear to\nyou what the outcome of it will be.  What values will `$w` take?\nHowever, with **shellcheck-repl** enabled, we will get the following\nif we try call it:\n\n```sh\n$ for w in \"$words\"; do echo \"$w\"; done\n           ^-- SC2066: Since you double quoted this, it will\n           not word split, and the loop will only run once.\n```\n\nSo, what [SC2066] suggests is that the output will be a single line\n`lorem ipsum dolor` and not three words on three separate lines.  We\nprobably meant to use:\n\n```sh\n$ for w in $words; do echo \"$w\"; done\nlorem\nipsum\ndolor\n```\n\n\n## Bypassing the ShellCheck validation\n\nYou can bypass the ShellCheck validation by appending two spaces to\nthe command with.  For instance, assume we get:\n\n```sh\n$ words=\"lorem ipsum dolor\"\n$ echo $words\n       ^-- SC2086: Double quote to prevent globbing and word splitting.\n```\n\nIdeally we should call:\n\n```sh\n$ echo \"$words\"\nlorem ipsum dolor\n```\n\nbut if we find that too tedious, we can skip the validation by\nappending two or more spaces at the end:\n\n```sh\n$ echo $words␣␣\nlorem ipsum dolor\n```\n\nBy the way, one example where [SC2086] is crucial is when you work\nwith filenames.  Using:\n\n```sh\n$ rm $file␣␣\n```\n\ncan be very risky if `$file` contains spaces - in addition to not\nremoving the file intended, you might end up removing files that you\ndid not intend to remove.\n\n\n## Disable and enable checks\n\nTo disable the ShellCheck REPL tool, do:\n\n```sh\n$ sc_repl_disable\n```\n\nTo reenable it, do:\n\n```sh\n$ sc_repl_enable\n```\n\n\n## Settings\n\n### ShellCheck rules to ignore\n\nSome of the ShellCheck rules may be too tedious to follow when on the\ncommand line.  For example, when trying to change directory to a\nnon-existing directory, `cd` will produce a non-zero exit code.  If\nyou do not handle this type of error in a script, ShellCheck will\nreport on [SC2164];\n\n```sh\ncd /path/to\n^-- SC2164: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.\n```\n\nThe suggestion is really valid for scripts, but for the command line\nit is just annoying.  Because of this, **shellcheck-repl** disables\nthe check for SC2164 by default.  In addition, it also disables the\nvalidation of other ShellCheck rules that are too tedious or simply\nfalse-positives when used at the command line. Here is the complete\nlist:\n\n* [SC1001]: This \\= will be a regular '=' in this context.\n* [SC1090]: Can't follow non-constant source. Use a directive to\n  specify location.\n* [SC1091]: Not following: (error message here).\n* [SC1113]: Use #!, not just #, for the shebang.\n* [SC2034]: 'var' appears unused. Verify it or export it.\n* [SC2096]: On most OS, shebangs can only specify a single parameter.\n* [SC2155]: Declare and assign separately to avoid masking return\n  values.\n* [SC2164]: Use 'cd ... || exit' or 'cd ... || return' in case cd\n  fails.\n\nThis set of rules that are disabled by default can be configured via\nenvironment variable `SHELLCHECK_REPL_EXCLUDE` by specifying rules\n(without `SC` prefix) as a comma-separated list.  The default\ncorresponds to\n`SHELLCHECK_REPL_EXCLUDE=1001,1090,1091,1113,2034,2155,2164`.\n\n\n### Disable and enable hints\n\nWhen there's a ShellCheck issue, a hint on how to disable that issue\nis also outputted, e.g.\n\n```sh\n$ msg=\"Value: $value\"\n              ^----^ SC2154 (warning): value is referenced but not assigned.\n\nTo skip a check, add its SC number to 'SHELLCHECK_REPL_EXCLUDE', e.g.\n\n  export SHELLCHECK_REPL_EXCLUDE=\"${SHELLCHECK_REPL_EXCLUDE},4038\"\n\nCurrently, SHELLCHECK_REPL_EXCLUDE=1001,1090,1091,1113,2034,2155,2164\n\nTo skip ShellCheck validation for this call, append two spaces\n```\n\nThis message can be disabled by setting:\n\n```sh\nSHELLCHECK_REPL_VERBOSE=false\n```\n\n\n\n## Requirements\n\n* [ShellCheck]\n* [Bash] (\u003e= 4.4)\n\nBash is the only supported shell right now.\n\n\n## Installation\n\nDownload the `shellcheck-repl.bash` script and source it in your\n`~/.bashrc` startup script, e.g.\n\n```sh\n$ curl -L -O https://github.com/HenrikBengtsson/shellcheck-repl/archive/refs/tags/0.4.3.tar.gz\n$ tar xf 0.4.3.tar.gz\n$ echo \". /path/to/software/shellcheck-repl-0.4.3/shellcheck-repl.bash\" \u003e\u003e ~/.bashrc\n```\n\nOr, similarly, via Git:\n\n```sh\n$ cd /path/to/software\n$ git clone https://github.com/HenrikBengtsson/shellcheck-repl.git\n$ echo \". /path/to/software/shellcheck-repl/shellcheck-repl.bash\" \u003e\u003e ~/.bashrc\n```\n\n\n## Authors\n\n* GitHub user [xPMo](https://github.com/xPMo) - [original code from 2019-03-28](https://github.com/koalaman/shellcheck/issues/1535#issuecomment-477633465)\n* Henrik Bengtsson\n\n\n## Appendix\n\n### Example: ShellCheck REPL prevents Bash fork bomb\n\nA well-known [fork bomb](https://en.wikipedia.org/wiki/Fork_bomb) in Bash is `:(){ :|:\u0026 };:`.  If launched, it will recursively relaunch itself via piping and background jobs.  With ShellCheck REPL enable, we will be prevented from executing the call, e.g.\n\n```sh\n$ :(){ :|:\u0026 };:\n     ^-- SC2264 (error): This function unconditionally re-invokes itself. Missing 'command'?\n       ^-- SC2264 (error): This function unconditionally re-invokes itself. Missing 'command'?\n```\n\n\n[ShellCheck]: https://github.com/koalaman/shellcheck\n[Bash]: https://www.gnu.org/software/bash/\n[SC2066]: https://github.com/koalaman/shellcheck/wiki/SC2066\n[SC2086]: https://github.com/koalaman/shellcheck/wiki/SC2086\n[SC1001]: https://github.com/koalaman/shellcheck/wiki/SC1001\n[SC1090]: https://github.com/koalaman/shellcheck/wiki/SC1090\n[SC1091]: https://github.com/koalaman/shellcheck/wiki/SC1091\n[SC1113]: https://github.com/koalaman/shellcheck/wiki/SC1113\n[SC2034]: https://github.com/koalaman/shellcheck/wiki/SC2034\n[SC2096]: https://github.com/koalaman/shellcheck/wiki/SC2096\n[SC2155]: https://github.com/koalaman/shellcheck/wiki/SC2155\n[SC2164]: https://github.com/koalaman/shellcheck/wiki/SC2164\n[#21]: https://github.com/HenrikBengtsson/shellcheck-repl/issues/21\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhenrikbengtsson%2Fshellcheck-repl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhenrikbengtsson%2Fshellcheck-repl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhenrikbengtsson%2Fshellcheck-repl/lists"}