Passing arguments to Python from Bash

I am parsing command line arguments in simple python program.

It works when i type:  python myFile.py -a foo -b bar

I tried to simplify its execution with a bash wrapper.

------begin wrapper-------
#!/usr/bin/bash
python myFile.py
------end wrapper-------

wrapper -a foo -b bar

When I do that my script doesn't take the arguments properly.  Whats happening, and how do I fix this?

tmonteitAsked:
Who is Participating?
 
TintinConnect With a Mentor Commented:
If you want to use a wrapper (have no idea why you would)

#!/usr/bin/bash
python myFile.py "$@"

or why not simply make sure myFile.py has

#!/usr/bin/python

as the first line, then you don't need the wrapper.
0
 
rami78Commented:
You will need something like that:

------begin wrapper-------
#!/usr/bin/bash
python myFile.py $*
------end wrapper-------

To be able to use:

wrapper -a foo -b bar
0
 
tmonteitAuthor Commented:
That is closer but I found a small problem.  When I try that and use the wrapper arguments that are passed in a string format get truncated.
wrapper -a "Foo ABC"
gets truncated into wrapper -a Foo
Sorry I should have specified that some of my arguments are strings.
 
 
0
All Courses

From novice to tech pro — start learning today.