All Projects → sharkdp → pysh

sharkdp / pysh

Licence: other
Python-enhanced bash scripts

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects

pysh

Python-enhanced bash scripts.

Build Status

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:

##### 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() + ext

    echo "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.csv

before: important.csv
after:  IMPORTANT.csv

Caveats

This is only supported for Python 3.4 and above due to redirect_stdout.

Disclaimer / warning

This is a prototype implementation with lots of evil hacks.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].