Skip to content

UnixEnvVarCommand

Base classes

Name Children Inherits
EnvVarCommand
anyenv.os_commands.base
Base class for environment variable commands.

⋔ Inheritance diagram

graph TD
  2942607473["env_var.UnixEnvVarCommand"]
  931535557["base.EnvVarCommand"]
  925645236["abc.ABC"]
  2751680898["builtins.object"]
  931535557 --> 2942607473
  925645236 --> 931535557
  2751680898 --> 925645236

🛈 DocStrings

Bases: EnvVarCommand

Unix/Linux environment variable command implementation.

Source code in src/anyenv/os_commands/env_var.py
class UnixEnvVarCommand(EnvVarCommand):
    """Unix/Linux environment variable command implementation."""

    def create_command(self, name: str) -> str:
        """Generate Unix printenv command.

        Args:
            name: Name of environment variable

        Returns:
            The printenv command string
        """
        return f"printenv {sh_quote(name)}"

    def parse_command(self, output: str, exit_code: int = 0) -> str | None:
        """Parse Unix printenv result.

        Args:
            output: Raw command output
            exit_code: Command exit code

        Returns:
            Variable value or None if not set
        """
        if exit_code != 0:
            return None
        # printenv includes trailing newline
        return output.rstrip("\n") if output else None

create_command

create_command(name: str) -> str

Generate Unix printenv command.

Parameters:

Name Type Description Default
name str

Name of environment variable

required

Returns:

Type Description
str

The printenv command string

Source code in src/anyenv/os_commands/env_var.py
def create_command(self, name: str) -> str:
    """Generate Unix printenv command.

    Args:
        name: Name of environment variable

    Returns:
        The printenv command string
    """
    return f"printenv {sh_quote(name)}"

parse_command

parse_command(output: str, exit_code: int = 0) -> str | None

Parse Unix printenv result.

Parameters:

Name Type Description Default
output str

Raw command output

required
exit_code int

Command exit code

0

Returns:

Type Description
str | None

Variable value or None if not set

Source code in src/anyenv/os_commands/env_var.py
def parse_command(self, output: str, exit_code: int = 0) -> str | None:
    """Parse Unix printenv result.

    Args:
        output: Raw command output
        exit_code: Command exit code

    Returns:
        Variable value or None if not set
    """
    if exit_code != 0:
        return None
    # printenv includes trailing newline
    return output.rstrip("\n") if output else None

:fa-brands-github: Show source on GitHub