shellshock¶
Contents:
Getting Started¶
A walkthrough highlighting the main features of Shellshock
Hello World¶
To start, we’ll create the Hello World of Python/Shell scripts. Let’s create a Python file called script.py that has the following contents:
print('Hello world!')
Now, you can convert this to a shell script using the Shellshock CLI. Without any arguments, Shellshock will output the resulting shell script to stdout.
$ shellshock script.py
echo 'Hello world!'
If you want, you can even pipe the output to your favorite shell to run it.
$ shellshock script.py | bash
Hello world!
Python feature compatability¶
Python Feature | Shellshock Support | Example |
---|---|---|
Strings | YES | "here we go"
|
Integers/Floats | YES | my_val = 3.14
|
Function definitions | YES | def doit(var1, var2='default'):
print(var1)
print(var2)
doit('once', 'twice')
|
Testing¶
Finally, you can unit test your shell scripts!
Converters¶
Converter Reference¶
Shellshock comes with many useful converter functions built-in. Here is the reference of these functions.
Examples are provided for most functions. For examples assume script.py is the input Shellshock script and script.sh is the output after Shellshock transpilation.
-
ss.
shell
(raw_shell_cmd)¶ Run a raw shell command. The argument will be output in its entirety.
Use this method when you want to write regular shell commands in your script.
Example: Basic Usage
script.py¶import shellshock as ss ss.shell("chown 755 myfile")
script.sh¶#!/bin/sh chown 755 myfile
Example: Convert Existing ScriptWrap an entire existing shell script (or a part of a script) in ss.shell to partially migrate an existing script to Shellshockscript.py¶import shellshock as ss ss.shell(""" chown 755 myfile # other existing shell script echo "output" """)
script.sh¶#!/bin/sh chown 755 myfile # other existing shell script echo "output"
CLI Reference¶
CLI command reference
Installation¶
pip install shellshock
Usage¶
shellshock script.py -o script.sh