Welcome to the new home of bash2py, a software tool that translates Bash shell code into Python.
For an overview of the project's status and current capabilities, please refer to the document Bash2pyManual.html.
This document is a color-coded version of the Bash reference manual that shows which Bash constructs we have specifically addressed.
Items highlighted in green have been addressed and are likely to be transpiled correctly, those in orange may translate correctly
some of the time, and those in red are not expected to work yet. Text in purple provides additional commentary.
You can install and run bash2py on Linux, Windows, Mac and Android.
Steps:
-
Download this software package.
-
Set up the standard GNU toolchain for building C-language projects (
gcc,make,autoconf).-
Building on Windows? We recommend the
CygwinUnix emulation layer and thebash-develandcygwin-develpackages to provide all required header files. -
Building on Android? The standard GNU toolchain is adequate to build the project except for at least one symbol (mblen) that is missing from the
libcsystem library. You can download this code from https://github.com/termux/libandroid-support and build and link it to create the executable.
-
-
cdinto the bash2py project and run./install.sh.- This will build
bash2py [.exe].
- This will build
-
Run bash2py:
./bash2py shellScript [...]
Bash2py will tell you where it's writing its Pythonic output: the same directory as the corresponding input script(s) using the same basename but a .py extension.
It will also write semi-customizable program trace logs to your screen.
Bash2py is a work in progress. We offer no warranty or guarantees as to its output. Please backup any input files before running.
It is a violation of federal law to use this software in a manner inconsistent with its labeling. Try it, but do not inhale.
The fundamental idea of bash2py is to replace bash's command execution loop with a transpile-and-print loop.
We would like to cover as much bash functionality as possible by altering and extending the native Bash source code. We are using a preprocessor macro "BASH2PY" to segregate our changes from the original.
The most significant changes and additions are contained in the following source files:
-
(Added) fix_string.c
- Alternative expansion and substitution algorithms that enable us to render bash value-expressions in python. "foo${x}" becomes 'foo'+x, etc.
-
(Added) translate.c
- Translates bash command syntax into python equivalents; "echo ..." becomes "print('...')", etc. Derived from bash's print_cmd.c.
-
(Added) translate_expr.c
- Translates arithmetic expressions. This is an adaptation of bash's expr.c. Instead of performing computations, we reformat bash arithmetic expressions into equivalent Python expressions.
-
(Changed & added) burp.c, dynamo.c
- These files implement the buffering, logging and code generation subsystems for the transpiler.
The bash source code comes from bash-4.3.30 but a forward port is on the agenda.
Please reach out to the project maintainer via this online repository. The historical project coordinator, Ian Davis of the University of Waterloo, is no longer maintaining the project.
Visit the original project home here.
-- Michael Wood