How would I pass a Python variable to the Bash shell? It should work like this:
foo="./RetVar.py 42"
Replace the double-quotes with `s
I have tried printing and sys.exiting the result, but to no avail. How would I accomplish my goal?
foo="$(scriptthatprintssomething)"
That's it. print. Or sys.stdout.write(). Or the like. If the script isn't executable then you'll need to specify the interpreter explicitly.
foo="$(python scriptthatprintssomething.py)"
In bash both ``cmd\ and $(cmd) will be replaced by the output of the command. This allows you to assign the output of a program to a variable like
foo=`some command`
or
foo=$(some command)
Normally you wrap this in double quotes so you can have spaces in your output. It must be double quotes as stuff inside single quotes will not be executed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With