Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sharkdp/pysh
Python-enhanced bash scripts
https://github.com/sharkdp/pysh
bash python shell-script
Last synced: about 10 hours ago
JSON representation
Python-enhanced bash scripts
- Host: GitHub
- URL: https://github.com/sharkdp/pysh
- Owner: sharkdp
- Created: 2017-03-04T13:39:53.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-19T19:03:10.000Z (about 6 years ago)
- Last Synced: 2024-05-08T22:46:23.609Z (6 months ago)
- Topics: bash, python, shell-script
- Language: Python
- Size: 8.79 KB
- Stars: 60
- Watchers: 8
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# pysh
Python-enhanced bash scripts.[![Build Status](https://travis-ci.org/sharkdp/pysh.svg?branch=master)](https://travis-ci.org/sharkdp/pysh)
`pysh` allows you to write bash scripts that include short snippets of Python
code with a local environment that is shared between bash and Python.## Example
Lines that start with `#> ` are evaluated as Python:
```bash
##### From bash to python #####bashVariable="Hello world"
#> print("{} from python!".format(bashVariable))##### From python to bash #####
#> pythonVariable = " ".join(["Hello", "world"])
echo "$pythonVariable from bash!"######## Back and forth #######
for file in *.csv; do
echo
echo "before: $file"#> base, ext = os.path.splitext(file)
#> file = base.upper() + extecho "after: $file"
done
```Run it:
```
> ls
dummy.csv important.csv example.sh> pysh example.sh
Hello world from python!
Hello world from bash!before: dummy.csv
after: DUMMY.csvbefore: important.csv
after: IMPORTANT.csv
```## Caveats
This is only supported for Python 3.4 and above due to [`redirect_stdout`](https://docs.python.org/3/library/contextlib.html#contextlib.redirect_stdout).
## Disclaimer / warning
This is a prototype implementation with lots of evil hacks.