0

I have two scripts: Python:

if canceled==True:
 os.environ["c"] = "0"
if canceled==False:
 os.environ["c"] = "1"

Bash:

kill_jobs()
{
 pkill -TERM -P "$BASHPID"
 echo $c
 if [ $c == "0" ]
 then
 echo -e "OPERATIONS CANCELED"
 elif [ $c == "1" ]
 then
 echo -e "OPERATIONS FINISHED"
 fi
}
trap kill_jobs EXIT

How can I do to pass a python variable to bash script ? (My level in bash is near to 0 ...) Thanks

Edit: Now I have this error: (in french)

[: == : opérateur unaire attendu
asked May 28, 2014 at 7:30

2 Answers 2

1

Or you can try:

os.environ["c"] = "value"

You can set it this way, I guess

Refer

answered May 28, 2014 at 7:38
Sign up to request clarification or add additional context in comments.

2 Comments

ok, your solution seems to work. I have another problem, I will edit my question.
either if [ $c -eq 0 ] or if [ "$c" == "0" ]. Please ask one question in one post. I haven't set this standard, but I guess that is what everyone follow here.
0

The python script should end with:

print c

Then you use it in bash with:

c=$(python_script)
answered May 28, 2014 at 7:35

2 Comments

Thanks for your answer, no need to pass in environment variable ?
No, just use ordinary shell variables. Environment variables are inherited by child processes.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.