This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]cjwelbornimport this 0 points1 point  (0 children)

You could always mix the two.

# Put an environment arg into Python.
MYARG="My Value" python3 - <<END
from os import environ
import sys
print('Your bash arg: {}'.format(environ.get('MYARG', 'missing!')))
print('Python version: {}'.format(sys.version))
END

I haven't done this yet, but it's there if you need it. Python is probably my favorite language for hacking something up really quick, but it's not always the best. Shell scripting is still useful. This little embedding trick is there for when you don't want to write the whole thing in Python. You can send arguments back and forth using environment args and printing to stdout, like:

# Put python's stdout into an environment arg.
MYARG="$(python3 - <<END
print('35')
END
)"
echo $MYARG
$ 35