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.echo

Source code for glxshell.utilities.echo

# Inspired by: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html
import sys
from glxshell.lib.argparse import ArgumentParser

parser_echo = ArgumentParser(
    name="echo - write arguments to standard output",
    description="The echo utility writes its arguments to standard output, followed by a <newline>. "
                "If there are no arguments, only the <newline> is written.",
)
parser_echo.add_argument(
    "-n",
    dest="newline",
    action="store_true",
    help="Suppress the <newline> that would otherwise follow the final argument in the output.",
)
parser_echo.add_argument(
    "string",
    nargs="*",
    type=str,
    help="A string to be written to standard outputself.\n",
)


[docs] def glxsh_echo(**kwargs): shell = kwargs.get("shell", None) newline = kwargs.get("newline", False) string = kwargs.get("string", "") try: value_to_return = str(string) if string.startswith('"') and string.endswith('"'): value_to_return = string[1:][:-1] for value in value_to_return.split(" "): if value.startswith("$"): value_to_return = value_to_return.replace(value, shell.environ.get(value.replace("$", ""), "")) if string.startswith("$") and " " not in string: value_to_return = string.replace(string, shell.environ.get(string.replace("$", ""), "")) sys.stdout.write(value_to_return) if not newline: sys.stdout.write("\n") return 0 except (Exception, BaseException) as error: sys.stderr.write(error) # stderr.write("echo: %s: '%s'\n" % (error_code_to_text(error.errno), string)) return 1

Top » Module code » glxshell.utilities.echo

© 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.