liveBook · Manning

Shell script

As explained in The Quick Python Book, Fourth Edition

A shell script is a text program interpreted by a command shell to execute commands and control operating-system operations.

A shell script is a text program interpreted by a command shell. A Python script launched from a shell is different: Python executes the file, while the shell starts the command and can redirect its input and output. section 11.0 section 11.2.3

> python replace.py zero 0 < infile > outfile

The shell starts `replace.py` through Python, passes `zero` and `0` as arguments, reads input from `infile`, and writes output to `outfile`. The command demonstrates shell redirection, not the contents of a shell script. section 11.2.3

Command-line execution varies by operating system. macOS can run Python scripts from a terminal; Windows offers Command Prompt, PowerShell, and a Linux environment through Windows Subsystem for Linux. On Windows, the Python executable may need to be added to PATH. section 11.2.2 section 11.2.3

The practical distinction is what interprets the file. The examples here use shell commands to run Python programs, but do not show shell-script syntax or how to write a shell program. section 11.2 section 11.6

How The Quick Python Book, Fourth Edition covers it

How deep it goes
Explains how to run Python scripts from shells and redirect streams, but does not teach shell-script syntax.
Examples
Uses a Windows command that runs `replace.py` with two arguments, input from `infile`, and output to `outfile`.
What it assumes
Assumes basic Python statements while allowing that command-line arguments and redirection may be unfamiliar.
What you can do after
Evaluate/understand it: distinguish a shell-launched Python script from a shell script and read a basic redirected command.
How it connects
Connects command shells to Python scripts, command-line arguments, input/output redirection, and PATH.

Also explained in

Compare how 6 books explain shell script →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Quick Python Book, Fourth Edition. The section links point to the parts of the book it draws on.