Script-arguments with spaces

Nils Kassube kassube at gmx.net
Sat Aug 18 20:03:54 UTC 2012


Karl Voit wrote:
> 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
> `----

> 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.

Well, I'm not familiar with gnome-terminal but with xterm this should 
work:

#!/bin/bash
/usr/bin/xterm -e /home/vk/tmp/2del/mytest/mypy.py "$@"


Nils




More information about the ubuntu-users mailing list