Consider the following Python script, script.py:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-a', type=int)
parser.add_argument('-b', type=int)
args = parser.parse_args()
print('a + b = {}'.format(args.a + args.b))
And the following shell script, runner.sh:
python3 script.py
I know I can run script.py like this $ python3 script.py -a 4 -b 6 to get the following result: a + b = 10, but I want to run script.py from within the shell script, and be able to pass -a and -b, like this: ./runner.sh -a 4 -b 6. However, when I try this, those arguments are not passed:
$ ./runner.sh -a 10 -b 6
Traceback (most recent call last):
File "script.py", line 10, in <module>
print('a + b = {}'.format(args.a + args.b))
TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType'
How can I pass arguments to a Python script that's wrapped inside a shell script? For what it's worth, I also tried sys.argv, to no avail.
python3 script.pyin a .sh file, as shown above.