update bash to xonsh

This commit is contained in:
a 2024-07-24 13:55:56 +02:00
parent ec5f4d8559
commit 29dfea3dde

View file

@ -1,11 +1,7 @@
Bash to Xonsh Translation Guide Bash to Xonsh Translation Guide
================================ ================================
As you have probably figured out by now, xonsh is not ``sh``-lang compliant. As you have probably figured out by now, xonsh is not POSIX compliant.
If your muscles have memorized all of the Bash prestidigitations, this page This page will help you put a finger on how to do the equivalent task in xonsh.
will help you put a finger on how to do the equivalent task in xonsh.
For shell scripts, the recommended file extension is ``xsh``, and shebang
line is ``#!/usr/bin/env xonsh``.
.. list-table:: .. list-table::
:widths: 30 30 40 :widths: 30 30 40
@ -14,6 +10,15 @@ line is ``#!/usr/bin/env xonsh``.
* - Bash * - Bash
- Xonsh - Xonsh
- Notes - Notes
* - No special object for represent session.
- ``__xonsh__``
- The ``__xonsh__`` object has all about current xonsh session e.g. ``__xonsh__.env``.
* - ``script.sh``
- ``script.xsh``
- The recommended file extension is ``.xsh``.
* - ``#!/bin/bash``
- ``#!/usr/bin/env xonsh``
- Use ``xonsh`` in the shebang.
* - ``echo --arg="val"`` * - ``echo --arg="val"``
``echo {}`` ``echo {}``
@ -33,7 +38,8 @@ line is ``#!/usr/bin/env xonsh``.
characters, words or brackets. characters, words or brackets.
* - ``IFS`` * - ``IFS``
- ``$XONSH_SUBPROC_OUTPUT_FORMAT`` - ``$XONSH_SUBPROC_OUTPUT_FORMAT``
- Changing the output representation and splitting. - Changing the output representation and splitting. Also take a look into ``DecoratorAlias``
to have an ability to return object e.g. ``j = $(@json echo '{}')``.
* - ``$NAME`` or ``${NAME}`` * - ``$NAME`` or ``${NAME}``
- ``$NAME`` - ``$NAME``
- Look up an environment variable by name. - Look up an environment variable by name.
@ -59,7 +65,7 @@ line is ``#!/usr/bin/env xonsh``.
* - ``ENV1=VAL1 command`` * - ``ENV1=VAL1 command``
- ``$ENV1=VAL1 command`` - ``$ENV1=VAL1 command``
or ``with ${...}.swap(ENV1=VAL1): command`` or ``with __xonsh__.env.swap(ENV1=VAL1): command``
- Set temporary environment variable(s) and execute the command. - Set temporary environment variable(s) and execute the command.
Use the second notation with an indented block to execute many commands in the same context. Use the second notation with an indented block to execute many commands in the same context.
* - ``alias ll='ls -la'`` * - ``alias ll='ls -la'``
@ -135,7 +141,7 @@ line is ``#!/usr/bin/env xonsh``.
- Xonsh publishes a handful of containers, primarily targeting CI and automation use cases. - Xonsh publishes a handful of containers, primarily targeting CI and automation use cases.
All of them are published on `Docker Hub <https://hub.docker.com/u/xonsh>`_. All of them are published on `Docker Hub <https://hub.docker.com/u/xonsh>`_.
* - ``exit 1`` * - ``exit 1``
- ``exit(1)`` - ``exit 1`` or ``exit(1)``
- Exiting from the current script. - Exiting from the current script.
To understand how xonsh executes the subprocess commands try To understand how xonsh executes the subprocess commands try