2016-02-04 22:37:45 -05:00
|
|
|
Bash to Xonsh Translation Guide
|
|
|
|
================================
|
2016-02-21 16:25:16 -05:00
|
|
|
As you have probably figured out by now, xonsh is not ``sh``-lang compliant.
|
2016-02-04 22:37:45 -05:00
|
|
|
If your muscles have memorized all of the Bash prestidigitations, this page
|
2017-06-07 11:51:06 -04:00
|
|
|
will help you put a finger on how to do the equivalent task in xonsh.
|
2016-02-04 22:37:45 -05:00
|
|
|
|
2019-01-29 13:44:49 +03:00
|
|
|
For shell scripts, the recommended file extension is ``xsh``, and shebang
|
|
|
|
line is ``#!/usr/bin/env xonsh``.
|
|
|
|
|
2016-05-07 13:40:55 -04:00
|
|
|
.. list-table::
|
2016-02-04 22:37:45 -05:00
|
|
|
:widths: 30 30 40
|
|
|
|
:header-rows: 1
|
|
|
|
|
|
|
|
* - Bash
|
|
|
|
- Xonsh
|
|
|
|
- Notes
|
|
|
|
* - ``$NAME`` or ``${NAME}``
|
|
|
|
- ``$NAME``
|
|
|
|
- Look up an environment variable by name.
|
2018-12-19 00:07:20 +11:00
|
|
|
* - ``export NAME=Peter``
|
|
|
|
- ``$NAME = 'Peter'``
|
|
|
|
- Setting an environment variable.
|
|
|
|
* - ``unset NAME``
|
|
|
|
- ``del $NAME``
|
|
|
|
- Unsetting/deleting an environment variable.
|
2016-06-07 23:19:31 -04:00
|
|
|
* - ``echo "$HOME/hello"``
|
|
|
|
- ``echo "$HOME/hello"``
|
|
|
|
- Construct an argument using an environment variable.
|
2016-06-04 17:20:06 -05:00
|
|
|
* - ``something/$SOME_VAR/$(some_command)``
|
|
|
|
- ``@('something/' + $SOME_VAR + $(some_command).strip())``
|
|
|
|
- Concatenate a variable or text with the result of running a command.
|
2016-06-07 23:19:31 -04:00
|
|
|
* - ``${!VAR}``
|
2016-02-04 22:37:45 -05:00
|
|
|
- ``${var or expr}``
|
2016-05-07 13:40:55 -04:00
|
|
|
- Look up an environment variable via another variable name. In xonsh,
|
2016-02-04 22:37:45 -05:00
|
|
|
this may be any valid expression.
|
|
|
|
* - ``$(cmd args)`` or ```cmd args```
|
2016-05-20 19:55:56 -04:00
|
|
|
- ``@$(cmd args)``
|
|
|
|
- Command substitution (allow the output of a command to replace the
|
|
|
|
command itself). Tokenizes and executes the output of a subprocess
|
|
|
|
command as another subprocess.
|
2016-02-04 22:37:45 -05:00
|
|
|
* - ``set -e``
|
|
|
|
- ``$RAISE_SUBPROC_ERROR = True``
|
2016-05-07 13:40:55 -04:00
|
|
|
- Cause a failure after a non-zero return code. Xonsh will raise a
|
2016-02-04 22:37:45 -05:00
|
|
|
``supbrocess.CalledProcessError``.
|
|
|
|
* - ``set -x``
|
|
|
|
- ``trace on``
|
|
|
|
- Turns on tracing of source code lines during execution.
|
2016-02-10 03:22:30 -05:00
|
|
|
* - ``&&``
|
|
|
|
- ``and`` or ``&&``
|
|
|
|
- Logical-and operator for subprocesses.
|
|
|
|
* - ``||``
|
|
|
|
- ``or`` as well as ``||``
|
|
|
|
- Logical-or operator for subprocesses.
|
2016-05-07 13:40:55 -04:00
|
|
|
* - ``$?``
|
2016-06-17 14:08:58 +03:00
|
|
|
- ``_.rtn``
|
2016-05-07 13:40:55 -04:00
|
|
|
- Returns the exit code, or status, of the previous command.
|
2016-06-21 00:32:22 +03:00
|
|
|
* - ``N=V command``
|
|
|
|
- ``with ${...}.swap(N=V): command``
|
2016-06-20 23:33:58 +03:00
|
|
|
- Set temporary environment variable(s) and execute for command.
|
|
|
|
Use an indented block to execute many commands in the same context.
|
2016-09-02 13:33:45 +03:00
|
|
|
* - ``!$``
|
2018-09-30 13:59:08 -07:00
|
|
|
- ``__xonsh__.history[-1, -1]``
|
2016-09-02 13:33:45 +03:00
|
|
|
- Get the last argument of the last command
|
2017-10-09 12:09:29 -04:00
|
|
|
* - ``$<n>``
|
|
|
|
- ``$ARG<n>``
|
|
|
|
- Command line argument at index ``n``,
|
|
|
|
so ``$ARG1`` is the equivalent of ``$1``.
|
|
|
|
* - ``$@``
|
|
|
|
- ``$ARGS``
|
|
|
|
- List of all command line argument and parameter strings.
|