Reputation: 573
a.py:
for arg in sys.argv:
print arg
b.sh:
python a.py $*
situation 1:
python a.py "123 456"
get:
123 456
situation 2:
/bin/sh b.sh "123 456"
get:
123
456
It seems "123 456" will pares in two args,how can i modify b.sh, make a.py can treat "123 456" as one arg.
Upvotes: 0
Views: 74
Reputation: 2495
Argparse sample related to my comment. Greatly simplifies legwork required
import argparse
parser = argparse.ArgumentParser(description='Test ')
parser.add_argument('first',help="The First argument", type=str)
parser.add_argument('second',help="the second argument",type=str)
args = parser.parse_args()
Upvotes: 0
Reputation: 212504
You need quotes:
python a.py "$*"
Also, if you use "$@"
instead of "$*"
it will expand to a multiple arguments.
Upvotes: 5