Skip to main content
Yanked

This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
Consider using release 1.5.4 instead.
Reason given by maintainers: Serious bug on stat format

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')

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shellingham-1.5.1.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

shellingham-1.5.1-py2.py3-none-any.whl (9.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file shellingham-1.5.1.tar.gz.

File metadata

  • Download URL: shellingham-1.5.1.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.9

File hashes

Hashes for shellingham-1.5.1.tar.gz
Algorithm Hash digest
SHA256 41bc81fa8d74afb04338e0398f9732ee2217407ade778ae1e2709bde89d85c45
MD5 9d8ea67966df03a449deb2c931962c52
BLAKE2b-256 1bb58a4ebd9108ab4f78e697a901969f3c3bf27afddf734a4b8a2e7dd7d440e3

See more details on using hashes here.

File details

Details for the file shellingham-1.5.1-py2.py3-none-any.whl.

File metadata

  • Download URL: shellingham-1.5.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.9

File hashes

Hashes for shellingham-1.5.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ce5f6d0062c719deabf696bccfab5273e09a6ea1b0ed32867aff03392adbdc51
MD5 31e1b3d5a6b8d5af54eb707c7dd0c888
BLAKE2b-256 896e41614878c7e964c907016418a8493a5508253727a15862a79992940ac9c3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page