Skip to main content

A cross-platform POSIX-style shell written in Python.

Project description

py-posix-shell

py-posix-shell is a cross-platform POSIX-style shell implemented in pure Python. The long-term goal is to become a practical dash-like shell that can run on Windows, Linux, and macOS from the same Python package.

It is still young, but it now supports the pieces needed by many ordinary shell scripts:

  • command lists with ;, &&, ||, background &, and !
  • pipelines with |
  • if/elif/else/fi
  • for, while, and until loops with break and continue
  • case/esac
  • POSIX-style functions with return
  • grouping with { ...; } and subshells with ( ... )
  • quoting with single quotes, double quotes, and backslash escapes
  • parameter expansion such as $HOME, $?, ${name:-word}, ${name:=word}, ${#name}, ${name#pattern}, ${name##pattern}, ${name%pattern}, and ${name%%pattern}
  • arithmetic expansion with $(( expression ))
  • command substitution with $(...) and backticks
  • field splitting, pathname expansion, tilde expansion, and set -f
  • here-documents with << and <<-
  • redirection with <, >, >>, <>, 2>, 2>>, >&, and <&
  • interactive filename completion with Tab
  • shell variables, exported environment variables, and positional parameters
  • common builtins including ., :, alias, unalias, cd, pwd, eval, exec, exit, export, readonly, unset, set, shift, getopts, echo, printf, read, type, command, env, test, [, trap, umask, times, hash, and history
  • internal POSIX/GNU-style utility fallbacks for hosts such as Windows where commands may be missing. The shell prefers a native command when it exists and otherwise falls back to Python implementations of common tools including ls, cat, cp, mv, rm, install, unlink, mkdir, rmdir, pwd, sort, uniq, wc, cut, head, tail, chmod, chown, chgrp, echo, date, sleep, printf, basename, dirname, whoami, yes, clear, help, find, xargs, locate, updatedb, diff, cmp, diff3, sdiff, grep, egrep, fgrep, sed, awk, gawk, base64, tr, vi, and tar

The implementation intentionally remains dependency-free at runtime. It aims for useful POSIX behavior first, then progressively tighter compatibility with dash.

Known gaps include job control, full signal semantics, complete interactive line editing, and exact set -e edge cases.

Installation

From PyPI:

pip install py-posix-shell

From this repository:

pip install .

For editable development:

pip install -e ".[dev]"

Usage

Start an interactive shell:

pysh

Run one command:

pysh -c "name=world; echo \"hello $name\""

Run a script:

pysh ./script.sh arg1 arg2

The package also installs the longer py-posix-shell command.

Development

Run the tests with:

pytest

Build the package with:

poetry build

Project details


Download files

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

Source Distribution

py_posix_shell-0.4.21.tar.gz (708.2 kB view details)

Uploaded Source

Built Distribution

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

py_posix_shell-0.4.21-py3-none-any.whl (71.8 kB view details)

Uploaded Python 3

File details

Details for the file py_posix_shell-0.4.21.tar.gz.

File metadata

  • Download URL: py_posix_shell-0.4.21.tar.gz
  • Upload date:
  • Size: 708.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.11.15 Windows/10

File hashes

Hashes for py_posix_shell-0.4.21.tar.gz
Algorithm Hash digest
SHA256 42ed0844f1e13c992484a9399c0b937888bdc2247437df9ff7f2b2b95fcc8888
MD5 5f2d87a5ab3399a0c7a90c3b8598eb9a
BLAKE2b-256 71f30848e50e2de08770c0ea9d41a4c7e0e8ab30fbeb7b5bcd89cdc0d52436e6

See more details on using hashes here.

File details

Details for the file py_posix_shell-0.4.21-py3-none-any.whl.

File metadata

  • Download URL: py_posix_shell-0.4.21-py3-none-any.whl
  • Upload date:
  • Size: 71.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.11.15 Windows/10

File hashes

Hashes for py_posix_shell-0.4.21-py3-none-any.whl
Algorithm Hash digest
SHA256 930fa7be56d2b91441d0c367e761e58953befd1742d5dfe628285b8da320144c
MD5 0e734c73681892cf68db1af095fff83c
BLAKE2b-256 8e61e3424bd88026202eae4eb3358d7c77f903b9c63f9fdd137ae4381b9771a6

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