Script-arguments with spaces
Karl Voit
devnull at Karl-Voit.at
Sat Aug 18 18:43:53 UTC 2012
Hi!
I do have a stupid problem with quoting in a shell script. At least I
tend to think that the problem relates to quoting :-)
What I need: a python script should be called indirectly using a shell
script. The command line arguments are one to multiple file names and
should be handles correctly by the python script.
Following example demonstrates my problem:
,----[ directly calling the python scrip works ]
| vk at gary ~2d/mytest % ./mypy.py *png
| args: ['2012-08-01 this is with spaces 2.png', '2012-08-01 this is with spaces.png']
| press ENTER
| vk at gary ~2d/mytest %
`----
Calling the python script via a shell script does not work. The file
names containing spaces are being split up:
,----[ ./test.sh *png ]
| args: ['2012-08-01', 'this', 'is', 'with', 'spaces', '2.png']
| press ENTER
`----
How can I achieve that the file names are sent through without this
split-up problem?
Thank you very much!
Here are the scripts used above:
,----[ test.sh ]
| #!/bin/bash
| /usr/bin/gnome-terminal -e "/home/vk/tmp/2del/mytest/mypy.py ${@}"
| #end
`----
Opening a gnome-terminal is a requirement of my use case. It can be
replaced by any other terminal emulation if necessary.
»xterm -e /home/vk/tmp/2del/mytest/mypy.py ${@}« does not work either.
,----[ mypy.py ]
| #!/usr/bin/env python
| # -*- coding: utf-8 -*-
|
| from optparse import OptionParser
| parser = OptionParser()
| (options, args) = parser.parse_args()
|
| def main():
| print("args: " + str(args))
| raw_input("press ENTER")
|
| if __name__ == "__main__":
| main()
`----
--
Karl Voit
More information about the ubuntu-users
mailing list