0

I don't know if this is the correct form

num=8
num2=10
num=subprocess.check_output("num/2", shell=True)
num2=subprocess.check_output("num2+7", shell=True)
1
  • Bash doesnt have access to your python variables, try something like that subprocess.check_output("{}/2".format(num), shell=True) Commented Mar 16, 2021 at 10:36

1 Answer 1

1

'num/2' is just the string "num/2". If you want it to be the variable num, you need to interpolate it, e.g., with an f-string f'{num}/2'.

Also if you're trying to use bash for division, you'll have to add double parentheses for arithmetic expansion:

>>> num = 8
>>> subprocess.check_output(f'echo $(( {num}/2 ))', shell=True)
b'4\n'

Python first interpolates {num} into 8, and then sends echo $(( 8/2 )) to shell.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.