Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mattdodge/shellshock
Write and test your shell scripts using Python
https://github.com/mattdodge/shellshock
bash bash-script python shell shell-scripts
Last synced: about 1 month ago
JSON representation
Write and test your shell scripts using Python
- Host: GitHub
- URL: https://github.com/mattdodge/shellshock
- Owner: mattdodge
- Created: 2019-01-09T04:59:28.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-05-14T18:50:56.000Z (over 5 years ago)
- Last Synced: 2024-10-11T09:21:28.617Z (about 1 month ago)
- Topics: bash, bash-script, python, shell, shell-scripts
- Language: Python
- Homepage:
- Size: 299 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Write and test your shell scripts using Python
Shell scripts are great - they run on most *nix machines, they allow you interact with the file system easily, and they are light weight and don't require a massive runtime. However, the syntax is error prone and they are difficult to manage and test. Shellshock lets you write and test your shell scripts using the Python syntax and test cases you already know and love.## Installation
Writing with Shellshock requires Python. The shell scripts it outputs do not require Python to run though.
```bash
pip install shellshock
```## Usage
To convert a Python shellshock script to a regular shell script:
```bash
shellshock my_script.py -o my_script.sh
```That command would, for example, turn this Python script:
**my_script.py**
```python
myvar = 5
if myvar > 3:
print("Big number")
else:
print("Small number")
```
into this shell script:
**my_script.sh**
```bash
#!/bin/sh
myvar=5
if [ "$myvar" -gt 3 ]; then
echo -e 'Big number'
else
echo -e 'Small number'
fi
```## Starting with an existing shell script
Let's say you have an existing shell script you want to convert that looks like this:**oldscript.sh**
```bash
if [ -f "file" ]; then
echo "ok"
fi
```You can easily make this a shellshock script using the `ss.shell` method and a multiline string at the top of the file:
**oldscript.py**
```python
import shellshock as ss
ss.shell("""
if [ -f "file" ]; then
echo "ok"
fi
""")
```Then you could convert it to full Python shellscript syntax like so:
**newscript.py**
```python
import shellshock as ss
if ss.isfile("file"):
print("ok")
```## Full Documentation
To see more examples, CLI and library references, and extended documentation see the full docs at https://shellshock.readthedocs.io