{"id":9548,"library":"bash-kernel","title":"Bash Kernel for Jupyter","description":"bash-kernel is a Jupyter kernel that allows users to run Bash commands and scripts directly within Jupyter notebooks. It enables interactive shell scripting, making it convenient for tasks involving command-line tools, system administration, and data processing workflows that benefit from shell utilities. The current version is 0.10.0, and it has a moderate release cadence, with several minor releases and bug fixes in recent months.","status":"active","version":"0.10.0","language":"en","source_language":"en","source_url":"https://github.com/takluyver/bash_kernel","tags":["jupyter","kernel","bash","notebook","shell","cli"],"install":[{"cmd":"pip install bash_kernel","lang":"bash","label":"Install package"},{"cmd":"python -m bash_kernel.install","lang":"bash","label":"Install kernel spec"}],"dependencies":[{"reason":"Required to run and interact with Jupyter kernels.","package":"jupyter","optional":false}],"imports":[],"quickstart":{"code":"# First, install the kernel (if not already done):\n# pip install bash_kernel\n# python -m bash_kernel.install\n\n# After installation, open Jupyter Notebook or JupyterLab.\n# Create a new notebook and select the 'Bash' kernel.\n\n# Example usage in a Jupyter notebook cell with Bash kernel:\n\n# Print the current working directory\npwd\n\n# Assign a variable and use it\nNAME=\"Jupyter User\"\necho \"Hello, $NAME!\"\n\n# Execute a simple loop\nfor i in {1..3}; do\n  echo \"Count: $i\"\ndone\n\n# Example of using a command-line utility\nls -l /tmp\n","lang":"bash","description":"After installing the `bash_kernel` package and running the install command, launch Jupyter Notebook or JupyterLab. Create a new notebook and select the 'Bash' kernel. You can then run standard Bash commands directly in the cells."},"warnings":[{"fix":"Upgrade to bash-kernel version 0.9.2 or newer to benefit from improved SIGPIPE handling.","message":"Shell commands dealing with SIGPIPE might behave unexpectedly in a Jupyter environment compared to a standard terminal. This was addressed in recent versions (0.9.2+).","severity":"gotcha","affected_versions":"<0.9.2"},{"fix":"Upgrade to bash-kernel version 0.9.2 or newer. If issues persist, try avoiding trailing backslashes for line continuation, or ensure they are correctly escaped if intended to be part of an argument.","message":"Trailing backslashes at the end of a command in a cell, often used for line continuation in bash, might be stripped, leading to syntax errors or unexpected command execution.","severity":"gotcha","affected_versions":"<0.9.2"},{"fix":"Use `displayHTML \"<h1>My HTML Output</h1>\"` instead of `echo \"<h1>My HTML Output</h1>\"` for rich HTML rendering.","message":"To output HTML content to the Jupyter notebook, you must use the `displayHTML` function provided by the kernel, as standard bash `echo` will output raw HTML text.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Ensure you run `python -m bash_kernel.install` after `pip install bash_kernel`. If using virtual environments (venv, conda), ensure both commands are executed within the activated environment from which you launch Jupyter.","cause":"The bash_kernel was installed but its kernel spec was not registered with Jupyter, or Jupyter is running in an environment where the kernel spec is not visible.","error":"Kernel not found: bash"},{"fix":"First, run `pip install bash_kernel`. Check for any errors during the pip installation. If in a virtual environment, ensure it's activated.","cause":"The `bash_kernel` Python package was not successfully installed in the active environment.","error":"ModuleNotFoundError: No module named 'bash_kernel' (when running python -m bash_kernel.install)"},{"fix":"Check the `PATH` inside the notebook by running `echo $PATH`. If a command's directory is missing, you can add it to the `PATH` for the current session (e.g., `export PATH=$PATH:/usr/local/bin`) or ensure Jupyter is launched from an environment with a complete PATH.","cause":"The shell command you are trying to execute is not found in the PATH environment variable inherited by the Jupyter kernel.","error":"bash: command not found: <command_name>"},{"fix":"For highly complex scripts, consider saving them to a `.sh` file and then executing the script from the notebook (e.g., `./my_script.sh`). For simpler cases, experiment with quoting and escaping to ensure the command is interpreted as intended.","cause":"The Jupyter execution environment or specific kernel implementation details might alter the interpretation of highly complex bash syntax, particularly involving multiple redirections, heredocs, or interactive elements.","error":"Commands with complex redirections or special characters behave differently than in a pure terminal."}]}