0

I have a wrapper script command.sh as main launch script for my python application, primarily to set some environment variables like PYTHONPATH:

#!/bin/bash

export PYTHONPATH=lib64/python/side-packages
./command.py $*

command.py looks like this:

#!/usr/bin/python

import sys
print sys.argv

Calling the wrapper script like

$ ./command.sh a "b c"

results in ['./command.py', 'a', 'b', 'c'], where I need ['./command.py', 'a', 'b c']

How can I pass parameters which contain spaces to the python script?

Andreas Fester
  • 36,091
  • 7
  • 95
  • 123

1 Answers1

4

Use $@ instead of $*, and quote it with ":

#!/bin/bash

export PYTHONPATH=lib64/python/side-packages
./command.py "$@"

See bash(1), section "Special Parameters", for more information.

Andreas Fester
  • 36,091
  • 7
  • 95
  • 123
  • 1
    You might want to look at http://stackoverflow.com/questions/9994295/what-does-mean-in-a-shell-script/9995322#9995322 for more information on this. – Alfe Mar 27 '13 at 14:43