Registry / devops / bash-kernel

bash-kernel

JSON →
library0.10.0pypypiunverified

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.

pip install bash_kernel
INSTALL
IMPORT
SIG · BASH-KERNEL
B
bash-kernel
devopspythonv0.10.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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.

# First, install the kernel (if not already done): # pip install bash_kernel # python -m bash_kernel.install # After installation, open Jupyter Notebook or JupyterLab. # Create a new notebook and select the 'Bash' kernel. # Example usage in a Jupyter notebook cell with Bash kernel: # Print the current working directory pwd # Assign a variable and use it NAME="Jupyter User" echo "Hello, $NAME!" # Execute a simple loop for i in {1..3}; do echo "Count: $i" done # Example of using a command-line utility ls -l /tmp
Debug
Known issues
gotchaShell 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+).
fix
Upgrade to bash-kernel version 0.9.2 or newer to benefit from improved SIGPIPE handling.
affects: <0.9.2
gotchaTrailing 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.
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.
affects: <0.9.2
gotchaTo 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.
fix
Use `displayHTML "<h1>My HTML Output</h1>"` instead of `echo "<h1>My HTML Output</h1>"` for rich HTML rendering.
affects: All versions
Errors
Common errors & fixes
Kernel not found: bash
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.
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.
ModuleNotFoundError: No module named 'bash_kernel' (when running python -m bash_kernel.install)
The `bash_kernel` Python package was not successfully installed in the active environment.
fix
First, run `pip install bash_kernel`. Check for any errors during the pip installation. If in a virtual environment, ensure it's activated.
bash: command not found: <command_name>
The shell command you are trying to execute is not found in the PATH environment variable inherited by the Jupyter kernel.
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.
Commands with complex redirections or special characters behave differently than in a pure terminal.
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.
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.
Upgrade
Version history
0.10.0latest on PyPI · released Jan 5, 2025
Audit
Dependencies
jupyterrequiredRequired to run and interact with Jupyter kernels.
Agent activity
29 hits · last 30 days
node
22
OpenAI (training)
1
Resources
bash-kernel — pip install bash-kernel · libregistry