Skip to main content
https://img.shields.io/pypi/v/shellingham.svg

Shellingham detects what shell the current Python executable is running in.

Usage

>>> import shellingham
>>> shellingham.detect_shell()
('bash', '/bin/bash')

detect_shell pokes around the process’s running environment to determine what shell it is run in. It returns a 2-tuple:

  • The shell name, always lowercased.

  • The command used to run the shell.

ShellDetectionFailure is raised if detect_shell fails to detect the surrounding shell.

Notes

  • The shell name is always lowercased.

  • On Windows, the shell name is the name of the executable, minus the file extension.

Notes for Application Developers

Remember, your application’s user is not necessarily using a shell. Shellingham raises ShellDetectionFailure if there is no shell to detect, but your application should almost never do this to your user.

A practical approach to this is to wrap detect_shell in a try block, and provide a sane default on failure

try:
    shell = shellingham.detect_shell()
except shellingham.ShellDetectionFailure:
    shell = provide_default()

There are a few choices for you to choose from.

  • The POSIX standard mandates the environment variable SHELL to refer to “the user’s preferred command language interpreter”. This is always available (even if the user is not in an interactive session), and likely the correct choice to launch an interactive sub-shell with.

  • A command sh is almost guaranteed to exist, likely at /bin/sh, since several POSIX tools rely on it. This should be suitable if you want to run a (possibly non-interactive) script.

  • All versions of DOS and Windows have an environment variable COMSPEC. This can always be used to launch a usable command prompt (e.g. cmd.exe on Windows).

Here’s a simple implementation to provide a default shell

import os

def provide_default():
    if os.name == 'posix':
        return os.environ['SHELL']
    elif os.name == 'nt':
        return os.environ['COMSPEC']
    raise NotImplementedError(f'OS {os.name!r} support not available')

Metadata

Release files for shellingham 1.5.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for shellingham 1.5.4
File Size Uploaded
shellingham-1.5.4.tar.gz 10.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for shellingham 1.5.4
File Interpreter ABI Platform
shellingham-1.5.4-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 20.1 kB

Release files / shellingham-1.5.4.tar.gz

Download URL shellingham-1.5.4.tar.gz
Size 10.3 kB
Tags Source
SHA-256 checksum
How to use checksums
8dbca0739d487e5bd35ab3ca4b36e11c4078f3a234bfce294b0a0291363404de
BLAKE2b-256 checksum
How to use checksums
58158b3609fd3830ef7b27b655beb4b4e9c62313a4e8da8c676e142cc210d58e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release files / shellingham-1.5.4-py2.py3-none-any.whl

Download URL shellingham-1.5.4-py2.py3-none-any.whl
Size 9.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
7ecfff8f2fd72616f7481040475a65b2bf8af90a56c89140852d1120324e8686
BLAKE2b-256 checksum
How to use checksums
e0f90595336914c5619e5f28a1fb793285925a8cd4b432c9da0a987836c7f822
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release history Release notifications | RSS feed

This release

1.5.4 This release

2 release files

1.5.3

2 release files

1.5.2

2 release files

1.5.1

2 release files

1.5.0

2 release files

1.4.0

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.8

2 release files

1.2.7

2 release files

1.2.6

2 release files

1.2.5

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page