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
Guillaume
  • 2,752
  • 5
  • 27
  • 42

2 Answers2

1

Or you can try:

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

You can set it this way, I guess

Refer

PradyJord
  • 2,136
  • 12
  • 19
  • ok, your solution seems to work. I have another problem, I will edit my question. – Guillaume May 28 '14 at 08:24
  • 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. – PradyJord May 28 '14 at 09:24
0

The python script should end with:

print c

Then you use it in bash with:

c=$(python_script)
Barmar
  • 741,623
  • 53
  • 500
  • 612