Skip to content

System Shell Utilities

Utilities for working with shell commands.

Shell Module

Shell command utilities.

This submodule provides utilities for safely handling shell commands, arguments, and escaping.

Examples

from rite.system.shell import shell_escape, shell_split shell_escape("file name.txt") "'file name.txt'" shell_split("ls -la '/tmp/file.txt'") ['ls', '-la', '/tmp/file.txt']

Modules

shell_escape

Shell Escape

Escape shell argument.

Examples

from rite.system.shell import shell_escape shell_escape("file name.txt") "'file name.txt'"

Functions

shell_escape(arg: str) -> str

Escape shell argument for safe usage.

Parameters:

Name Type Description Default
arg str

Argument to escape.

required

Returns:

Type Description
str

Escaped argument string.

Examples:

>>> shell_escape("file name.txt")
"'file name.txt'"
>>> shell_escape("simple")
'simple'
Notes

Uses shlex.quote for proper escaping. Safe for shell command construction.

shell_join

Shell Join

Join command arguments into shell string.

Examples

from rite.system.shell import shell_join shell_join(["ls", "-la", "file name.txt"]) "ls -la 'file name.txt'"

Functions

shell_join(args: list[str]) -> str

Join command arguments into shell string.

Parameters:

Name Type Description Default
args list[str]

List of command arguments.

required

Returns:

Type Description
str

Shell command string.

Examples:

>>> shell_join(["ls", "-la"])
'ls -la'
>>> shell_join(["echo", "hello world"])
"echo 'hello world'"
Notes

Uses shlex.join for proper escaping. Python 3.8+ required for shlex.join.

shell_split

Shell Split

Split shell command string.

Examples

from rite.system.shell import shell_split shell_split("ls -la '/tmp/file name.txt'") ['ls', '-la', '/tmp/file name.txt']

Functions

shell_split(cmd: str) -> list[str]

Split shell command string into arguments.

Parameters:

Name Type Description Default
cmd str

Command string to split.

required

Returns:

Type Description
list[str]

List of command arguments.

Examples:

>>> shell_split("ls -la")
['ls', '-la']
>>> shell_split("echo 'hello world'")
['echo', 'hello world']
Notes

Uses shlex.split for proper parsing. Handles quoted arguments correctly.

options: show_root_heading: true show_source: false heading_level: 2