Skip to main content

myshell

A Unix-style shell written in Python. It runs on Linux and macOS with full job control. It also runs on Windows through a simpler fallback.

Requirements

  • Python 3.9 or newer. Tested on 3.9 and 3.13 on Linux, macOS and Windows (see .github/workflows/ci.yml).
  • prompt_toolkit is optional. With it you get Ctrl+R history search, grey suggestions and syntax colors. Without it the shell uses plain input() and readline.
  • pytest and pyflakes for development: pip install -e ".[dev]"

Install and run

uvx myshell                      run without installing (after the first release)
uv tool install myshell          install it
pip install myshell

From a clone:

python shell.py                  interactive shell
python shell.py -c "echo hi"     run one command string
python shell.py script.sh a b    run a script. $1 is a, $2 is b
python -m myshell                same thing, as a package
uv run myshell                   uses pyproject.toml

myshell -c 'cmd' NAME ARG... sets $0 to NAME and $1... to the ARGs.

Run the tests

pip install -e ".[dev]"
python -m pytest
python -m pyflakes myshell tests

With uv: uv run --extra dev pytest.

Release

uv build                         writes dist/*.whl and dist/*.tar.gz
uv publish                       needs a PyPI token or trusted publishing

Pushing a tag such as v0.2.0 runs .github/workflows/release.yml, which builds and publishes with trusted publishing. Add the repository as a trusted publisher on pypi.org first (project myshell, workflow release.yml, environment pypi). Bump version in pyproject.toml before each release. If the name myshell is taken when you publish, change name in pyproject.toml. The command stays myshell.

Features

Commands and operators

  • Pipes: a | b
  • Lists: a; b, a && b, a || b
  • Background jobs: a &
  • Comments with #

Quoting and expansion

  • Single quotes, double quotes and backslash escapes
  • Variables: $X, ${X}, $?, $$, and $0 $1 ... $# $@ $*
  • Parameter expansion: ${X:-default} ${X:=v} ${X:?msg} ${X:+alt} ${#X} ${X%.txt} ${X%%p} ${X#p} ${X##p} ${X/old/new} ${X//old/new} ${X:off:len} ${X^^} ${X,,}
  • Brace expansion: file.{txt,md}, {1..5}, {a..e}, {01..10}, {1..10..2}
  • Command substitution: $(cmd) and backticks
  • Arithmetic: $((1 + 2 * x)), including +=, ?:, hex and octal
  • Word splitting, globbing (*, ?, [ab]) and tilde (~)
  • Assignments: NAME=value, and NAME=value cmd for one command

Redirection

  • < > >> 2> 2>> &> &>>
  • 2>&1 and 1>&2, applied left to right
  • Here-strings: <<<
  • Here-documents: <<EOF and <<-EOF. A quoted delimiter such as <<'EOF' turns expansion off.

Control flow

  • if, elif, else, fi
  • while, until, for NAME in WORDS, with do and done. A bare for x; do loops over "$@".
  • case WORD in a|b) ...;; *.txt) ...;; *) ...;; esac
  • Functions: name() { ...; } or function name { ...; }, with $1, $@, $#, return and local
  • Groups: { a; b; }
  • break N and continue N
  • Blocks work on one line or across many lines

Builtins

  • echo (with -n -e -E), pwd cd exit alias unalias type which export unset source .
  • read (-r -p -d -n), printf (-v), set (-e -u -x, -o, --), shift local return
  • env (-i -u NAME=value), exec, trap (EXIT, INT, TERM, HUP, USR1, USR2)
  • true false :
  • jobs fg bg wait
  • test and [ ]: file, string and number checks, and !
  • history: N, -c, -d N, -w [file], -r [file]
  • guide: lessons, cheat sheet and tips

Commands that work on every system

  • ls cat head tr sleep mkdir rm cp mv touch wc grep are built in. A real program of the same name on your PATH wins, so on Linux and macOS you still get GNU or BSD tools. Where there is none (plain Windows), the built-in one runs. Set MYSHELL_PORTABLE=1 to always use the built-in ones.
  • They also work in pipes and $(...) without fork. This is what makes Pip's lessons run on Windows.

Interactive use

  • Job control: Ctrl+C, Ctrl+Z, fg, bg
  • Tab completion for commands, paths and function names
  • With prompt_toolkit: Ctrl+R reverse search, grey suggestion from history (Right arrow or End takes it), colors (green known command, red unknown, yellow strings, cyan variables). MYSHELL_EDITOR=basic turns it off.
  • After a command that takes longer than 2 seconds the shell prints took 3.2s. Set SLOW_COMMAND_SECS to change the limit, or to off.
  • Traps: trap 'cmd' EXIT runs when the shell ends
  • History saved in ~/.custom_shell_history, limited to 1000 entries
  • Startup file ~/.myshellrc
  • Prompt set with PS1. Continuation lines use PS2.

Pip, the guide

Pip is a small original character who lives in the shell.

,---.   .--------------------------------------.

( ^ ^ ) | Hi, I am Pip, your shell guide. | \ v / '--------------------------------------' (@)>

  • Greets you at startup with a tip. Only on a real terminal.
  • guide opens a menu of 13 lessons, with [x] next to the ones you finished. Each step shows a command. Press Enter to run it, s to skip, q to stop.
  • guide TOPIC jumps to one lesson. Names and numbers both work, for example guide pipes or guide 2.
  • guide cheat prints a cheat sheet. guide tip prints one tip. guide list lists the topics.
  • guide quiz [TOPIC] [N] asks N multiple-choice questions (default 5). guide progress shows finished lessons and best scores. guide progress reset clears them. Progress lives in ~/.myshell_progress.json.
  • Explains mistakes. A mistyped command gets "Did you mean ...?". An unclosed quote, $( or block gets a plain explanation.
  • guide off hides Pip for the session. Put GUIDE=off in ~/.myshellrc to hide Pip always.
  • Scripts, -c and piped input never show Pip's greeting or hints.

Prompt escapes

Escape Meaning
\w current directory, ~ for home
\W last part of the directory
\u \h user name, host name
\$ $, or # for root
\j running jobs
\? exit status of the last command
\n \e \\ newline, escape, backslash
\t \T \A \@ \d time (24-hour, 12-hour, HH:MM, am/pm), date
\g git branch of the current folder, empty outside a repository
\[ \] wrap colors so line editing counts width correctly

The default prompt adds the branch in brackets inside a git repository.

Example ~/.myshellrc:

PS1='\u@\h \W \$ '
PS2='more> '
alias ll='ls -l'

Layout

File Job
cli.py entry point, interactive loop
lexer.py text to tokens
parser.py tokens to a tree
expand.py variables, substitution, math, globbing
arith.py the $((...)) evaluator
heredoc.py here-document bodies
executor.py runs the tree with fork and pipes
jobs.py process groups and job control
builtins.py core builtin commands, lookup of builtins
more_builtins.py read, printf, set, env, which, trap, exec and friends
coreutils.py ls, cat, head, tr, sleep, mkdir, rm, cp, mv, touch, wc, grep
editor.py highlight.py optional prompt_toolkit line editor and syntax colors
progress.py quiz.py Pip's progress file and quiz questions
completion.py tab completion
prompt.py prompt escapes
guide.py Pip: lessons, hints, greeting
state.py variables, aliases, history, status
compat.py platform checks

Limits

  • Only file descriptors 0, 1 and 2 are redirected.
  • Here-documents do not work inside multi-line if, loop and function blocks.
  • Pipes, redirects and & after fi, done, esac or } are errors. So cmd | while read x; do ...; done does not work yet.
  • Function bodies must be { ...; } groups. There are no arrays, eval, select or [[ ]].
  • test has no -a, -o or parentheses.
  • On Windows there is no job control: & runs in the foreground and fg, bg and wait are unavailable. Pipelines that include built-in commands run one stage after the other, with each stage's output held in memory.
  • Signal traps run at the next command boundary, not in the middle of a command.

Metadata

Release files for myshell-py 0.2.0

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

Source distribution (sdist)

Source distribution for myshell-py 0.2.0
File Size Uploaded Provenance Actions
myshell_py-0.2.0.tar.gz 112.4 kB Without provenance Details for myshell_py-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for myshell-py 0.2.0
File Interpreter ABI Platform Actions
myshell_py-0.2.0-py3-none-any.whl Python 3 none any Details for myshell_py-0.2.0-py3-none-any.whl

Total release size: 193.7 kB

Release files / myshell_py-0.2.0.tar.gz

Download URL myshell_py-0.2.0.tar.gz
Size 112.4 kB
Tags Source
SHA-256 checksum
How to use checksums
5acc1a10466c5963d211aa216ecc040bb806f096c757cc8d42bc9043f31f7936
BLAKE2b-256 checksum
How to use checksums
59321297375ebcb6388885da1934b016231ee5d75746729c958b1c59b42b01a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / myshell_py-0.2.0-py3-none-any.whl

Download URL myshell_py-0.2.0-py3-none-any.whl
Size 81.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
776bb2cf9047871a00f9375702617dadf2f45f8e7061989b8403aff9853d775c
BLAKE2b-256 checksum
How to use checksums
21831c257c68e787af67179de78a9b855a324a360ac45e335838e720c6203f86
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for myshell-py 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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