#!/usr/bin/python
import sys
import subprocess
import yaml
yaml_blob = """
smoser_anchors:
- &foo_script |
echo "this blob is free from even yaml iterpretation"
cat <<"EOF"
you can use this as shown below
EOF
runcmd:
- echo this is interpreted by shell home=$HOME essentially by "sh -c string"
- [sh, -c, 'echo "this explicitly asks for shell interpretation"']
- [echo, 'this $& can have ** anything ($HOME) ** in it. its safe from shell']
- [sh, -c, *foo_script]
"""
data = yaml.load(yaml_blob)
for i in data['runcmd']:
if isinstance(i, str):
# strings get shell=True
subprocess.check_call(args=[i], shell=True)
else:
# lists do not get shell=True
subprocess.check_call(args=i)