简体   繁体   中英

Run python command inside a bash script and get the result

I would like to run a python command that return true or false inside a bash script:

#!/usr/bin/env bash

Some stuff...
boolean = $(python -c "bool(...operations...)")

The code above is just to sketch the idea. I need boolean to be false or true (bash boolean values) depending on the result of ...operations... . The code above is not working: boolean results to be an empty variable.

bool=$(python -c 'print(bool("abc"))') works as expected.

Note that this will return True or False not true or false (ie, capitalized).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM