You are not logged in.

#1 2010-07-30 10:28:36

hungerfish
Member
Registered: 2009-09-13
Posts: 254

parsing commandline args with bash[SOLVED]

Hi!

I need to know how I can 'parse' commandline args that my script receives 'onto' the executable that the script calls.

#!/bin/bash
xhost + local:
schroot -p -- firefox

As you can see, my script uses schroot to start up firefox (in my 32bit chroot, damn you adobe!)
This works fine, BUT, I want to have 'normal' behaviour, which means for example clicking on a link in a pidgin chat window actually opens that link.
For this to work, I set my script to be called in GNOME's preferred apps menu. Sadly all that happens is that a new firefox window is opened.

So I need to parse the  link, normally I would have:

firefox -new-tab "%s"

in the preferred apps menu.

So I need to modify my script to parse "%s". How would I do this??

Last edited by hungerfish (2010-07-30 11:25:03)


Beetles and bacteria are vastly more successful than humans in terms of survival.

Offline

#2 2010-07-30 10:44:05

hbekel
Member
Registered: 2008-10-04
Posts: 311

Re: parsing commandline args with bash[SOLVED]

I assume you want to pass the first argument to your script on to firefox:

#!/bin/bash
xhost + local:
schroot -p -- firefox -new-tab $1

Also see bash(1), "Positional Parameters"

Offline

#3 2010-07-30 11:25:31

hungerfish
Member
Registered: 2009-09-13
Posts: 254

Re: parsing commandline args with bash[SOLVED]

Hey, thanks works perfectly smile


Beetles and bacteria are vastly more successful than humans in terms of survival.

Offline

#4 2010-07-31 05:58:55

PirateJonno
Forum Fellow
From: New Zealand
Registered: 2009-04-13
Posts: 372

Re: parsing commandline args with bash[SOLVED]

this should work better:

schroot -p -- firefox "$@"

that way, all the arguments get passed to firefox


"You can watch for your administrator to install the latest kernel with watch uname -r" - From the watch man page

Offline

#5 2010-07-31 15:34:00

hungerfish
Member
Registered: 2009-09-13
Posts: 254

Re: parsing commandline args with bash[SOLVED]

Ok, cool!


Beetles and bacteria are vastly more successful than humans in terms of survival.

Offline

Board footer

Powered by FluxBB