GitHub
github.com › clarity20 › bash2py
GitHub - clarity20/bash2py: The only Bash-to-python transpiler you will ever need! https://www.swag.uwaterloo.ca/bash2py/index.html
Welcome to the new home of bash2py, a software tool that translates Bash shell code into Python.
Starred by 38 users
Forked by 17 users
Languages C 68.7% | HTML 15.9% | Yacc 6.6% | Shell 3.1% | Perl 2.6% | Makefile 2.1% | C 68.7% | HTML 15.9% | Yacc 6.6% | Shell 3.1% | Perl 2.6% | Makefile 2.1%
Uwaterloo
swag.uwaterloo.ca › bash2py › downloads › index.html
Bash2Py downloads
SWAG: Software Architecture Group · This tool makes a reasonable effort to convert Bash to Python
Stack Exchange
unix.stackexchange.com › questions › 627842 › problem-when-converting-bash-to-python-using-bash2py
shell script - Problem when converting bash to python using bash2py - Unix & Linux Stack Exchange
January 6, 2021 - Beginning configuration for bash-4.3-release for x86_64-unknown-linux-gnu checking for gcc... gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking for strerror in -lcposix... no ... ls -l bash -rwxr-xr-x 1 johannes johannes 5190160 jan 6 12:28 bash size bash text data bss dec hex filename 1093876 46840 24080 1164796 11c5fc bash mv bash bash2pyengine cp bash2pyengine ~/bin/bash2pyengine -rwxr-xr-x 1 johannes johannes 5190160 jan 6 12:28 bash2pyengine
IEEE Xplore
ieeexplore.ieee.org › document › 7081866
Bash2py: A bash to Python translator | IEEE Conference Publication | IEEE Xplore
At the request of our industrial ... converts bash scripts into Python. Bash2py leverages the open source bash code, and the internal parser employed by Bash to parse any bash script. However, bash2py re-implements the ...
Uwaterloo
swag.uwaterloo.ca › bash2py › Bash2pyManual.html
Bash2py Reference Manual
Bash2py is a rough and ready translator from Bash to Python.
Docker Hub
hub.docker.com › r › imiell › bash2py
imiell/bash2py
Welcome to the world's largest container registry built for developers and open source contributors to find, use, and share their container images. Build, push and pull.
University of Waterloo
cs.uwaterloo.ca › ~ijdavis › bash2py-final.pdf pdf
Bash2py: A Bash to Python Translator
Python code. Bash2py correctly converts most Bash into Python,
GitHub
github.com › ianmiell › bash2py
GitHub - ianmiell/bash2py: bash2py in a docker image, cf: http://www.swag.uwaterloo.ca/bash2py/index.html
Starred by 27 users
Forked by 16 users
GitHub
github.com › clarity20 › bash2py › blob › master › bash2py
bash2py/bash2py at master · clarity20/bash2py
Bash-to-python transpiler https://www.swag.uwaterloo.ca/bash2py/index.html - bash2py/bash2py at master · clarity20/bash2py
Author clarity20
Top answer 1 of 2
3
import os
for i in range(1, 50):
env_var = os.environ[f'{i}nl']
os.system(f"ssh BF-c{env_var} 'hostname; free -h; uname -a;'")
Python3.6 >
env_var = os.environ[str(i) + 'nl']
os.system("ssh BF-c{} 'hostname; free -h; uname -a;'".format(env_var))
2 of 2
2
You can do it using Bash2Py.
Also, you can try using the docker image
Courtesy: Bash to Python
So the below code is actually the complete script for conversion.
#! /usr/bin/env python
from __future__ import print_function
import sys,os
class Bash2Py(object):
__slots__ = ["val"]
def __init__(self, value=''):
self.val = value
def setValue(self, value=None):
self.val = value
return value
def GetVariable(name, local=locals()):
if name in local:
return local[name]
if name in globals():
return globals()[name]
return None
def Make(name, local=locals()):
ret = GetVariable(name, local)
if ret is None:
ret = Bash2Py(0)
globals()[name] = ret
return ret
def Array(value):
if isinstance(value, list):
return value
if isinstance(value, basestring):
return value.strip().split(' ')
return [ value ]
class Expand(object):
@staticmethod
def at():
if (len(sys.argv) < 2):
return []
return sys.argv[1:]
@staticmethod
def star(in_quotes):
if (in_quotes):
if (len(sys.argv) < 2):
return ""
return " ".join(sys.argv[1:])
return Expand.at()
@staticmethod
def hash():
return len(sys.argv)-1
if (Expand.hash() < 1 ):
print("Usage: "+__file__+" file ...")
exit(1)
print(__file__+" counts the lines of code")
l=Bash2Py(0)
for Make("f").val in Expand.star(0):
Make("l").setValue(os.popen("wc -l "+str(f.val)+" | sed \"s/^\\([0-9]*\\).*$/\\1/\"").read().rstrip("\n"))
print(str(f.val)+": "+str(l.val))
The guts of the code is in the for loop at the bottom.
bash2py does some safe conversion and wrapping of the bash script into some methods such as ‘Make’, ‘Array’ et al that we can get rid of with a little work.
By replacing:
Bash2Py(0)with0Make(“f”).valwithfandMake(“l”)withletcf.valwithfandl.valwithletc
GitHub
github.com › clarity20 › bash2py › blob › master › install
bash2py/install at master · clarity20/bash2py
Bash-to-python transpiler https://www.swag.uwaterloo.ca/bash2py/index.html - bash2py/install at master · clarity20/bash2py
Author clarity20
ResearchGate
researchgate.net › publication › 262315043_Python_scripts_as_a_replacement_for_bash_utility_scripts
Python scripts as a replacement for bash utility scripts
November 1, 2012 - Bash2py leverages the open source bash code, and the internal parser employed by Bash to parse any bash script. However, bash2py re-implements the variable expansion that occurs in Bash to better generate correct Python code.
grep Flags
zwischenzugs.com › 2016
2016 – zwischenzugs
#! /usr/bin/env python from __future__ import print_function import sys,os class Bash2Py(object): __slots__ = ["val"] def __init__(self, value=''): self.val = value def setValue(self, value=None): self.val = value return value def GetVariable(name, local=locals()): if name in local: return local[name] if name in globals(): return globals()[name] return None def Make(name, local=locals()): ret = GetVariable(name, local) if ret is None: ret = Bash2Py(0) globals()[name] = ret return ret def Array(value): if isinstance(value, list): return value if isinstance(value, basestring): return value.strip
ACM Digital Library
dl.acm.org › doi › 10.1145 › 3517193
Bash in the Wild: Language Usage, Code Smells, and Bugs | ACM Transactions on Software Engineering and Methodology
As mentioned in Section 1, there exist studies such as Bash2Py [10], NL2Bash [26], and NLC2CMD [2] (English to Bash) that attempt to convert Bash scripts to Python scripts or convert commands described in natural languages to Bash commands. One of the practicalities of these studies is that it avoids the overhead of developing and maintaining Bash scripts due to its less intuitive syntax and semantics.
GitHub
github.com › ianmiell › bash2py › blob › master › Dockerfile
bash2py/Dockerfile at master · ianmiell/bash2py
bash2py in a docker image, cf: http://www.swag.uwaterloo.ca/bash2py/index.html - ianmiell/bash2py
Author ianmiell
GitHub
github.com › syuanca › bash2python
GitHub - syuanca/bash2python: A tool that converts a bash script to python script
Starred by 22 users
Forked by 11 users
Languages Python 56.7% | Shell 43.3% | Python 56.7% | Shell 43.3%