FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Ubuntu > Ubuntu User

 
 
LinkBack Thread Tools
 
Old 08-18-2012, 06:43 PM
Karl Voit
 
Default Script-arguments with spaces

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


--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 08-18-2012, 08:03 PM
Nils Kassube
 
Default Script-arguments with spaces

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

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 08-18-2012, 11:37 PM
Karl Voit
 
Default Script-arguments with spaces

Hi Nils!

* Nils Kassube <kassube@gmx.net> wrote:
> Karl Voit wrote:
>> /usr/bin/gnome-terminal -e "/home/vk/tmp/2del/mytest/mypy.py ${@}"
>> xterm -e /home/vk/tmp/2del/mytest/mypy.py ${@}
>
> 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 "$@"

Yes! :-)

Thanks for your input!

The reason why I did not tried this one was that I thought that the
argument after «-e» has to be quoted to be recognized as one
single argument. I was wrong with this assumption when using xterm.

In xterm, «-e» has to be the *last* argument. This way, it is able
to do the trick as shown by your email.

For anybody who wants to do this with gnome-terminal as well: there
is an additional option «-x» which takes *remaining* command line as
one single argument just like the «-e» option of xterm does.

Annoying problem for me for too long but now I got it, thanks!

--
Karl Voit


--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 

Thread Tools




All times are GMT. The time now is 09:12 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2007 - 2008, www.linux-archive.org