Galaxie Shell 0.2.6 documentation


Navigation:   | Index   | Search   | Top   | Up   |
Table of Content: |

© Copyright 2020-2024, Galaxie Shell Team.

Top » Module code » glxshell.utilities.env

Source code for glxshell.utilities.env

# inspired by: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/env.html

import sys
import subprocess
from glxshell.lib.argparse import ArgumentParser


parser_env = ArgumentParser(
    name="env - set the environment for command invocation",
    description="The env utility shall obtain the current environment, modify it according to its arguments, "
    "then invoke the utility named by the utility operand with the modified environment.",
)
parser_env.add_argument(
    "-i",
    dest="invoke",
    action="store_true",
    help="Invoke utility with exactly the environment specified by the arguments; the inherited environment shall "
    "be ignored completely.",
)
parser_env.add_argument(
    "name",
    nargs="?",
    dest="name",
    help="Arguments of the form name= value shall modify the execution environment, and shall be placed into the "
    "inherited environment before the utility is invoked.",
)
parser_env.add_argument(
    "utility",
    nargs="?",
    dest="utility",
    help="The name of the utility to be invoked. If the utility operand names any of the special built-in "
    "utilities in Special Built-In Utilities, the results are undefined.",
)
parser_env.add_argument(
    "argument",
    nargs="?",
    dest="argument",
    help="A string to pass as an argument for the invoked utility.",
)


[docs] def glxsh_env(name, utility, argument, shell): if shell and hasattr(shell, "environ"): if name: try: func = getattr(shell, "do_" + utility) return func(argument) except AttributeError: try: pr = subprocess.run(utility, argument, env=shell.environ) return pr.returncode except (Exception, BaseException): return shell.default(utility) else: for name, value in shell.environ.items(): sys.stdout.write("%s=%s\n" % (name, value)) return 0

Top » Module code » glxshell.utilities.env

© Copyright 2020-2024, Galaxie Shell Team.
This page is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License (CC BY-NC-SA 4.0).
Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
See History and License for more information.

Last updated on None.
Created using Sphinx 8.0.2.