On 11/11/2007, Barry Miller <[EMAIL PROTECTED]> wrote:
> On Sun, Nov 11, 2007 at 10:32:05PM +0100, ropers wrote:
> > xterm -e "telnet ${1##telnet://}"
> >
> > When I click a telnet URL that does not specify a port, it works,
> > xterm launches with telnet, which duly connects to the port.
> >
> > However, if I click a telnet URL that *does* specify a port, it does
> > not work, xterm closes immediately. I've manually figured out that it
> > throws the error message
> >
> > telnet: could not resolve mud.vhdev.com:1991/telnet: Name or service not 
> > known
> >
> > before closing.
> >
> > man telnet told me that telnet expects to be given the port number
> > separated by a space, not divided by a colon.
> >
> > Currently, if I click on telnet://mud.vhdev.com:1991, telnet is called with
> >
> > telnet mud.vhdev.com:1991
> >
> > instead of
> >
> > telnet mud.vhdev.com 1991
> >
> > which would be correct.
>
> I think maybe sed, not awk.  Try:
>
>         xterm -e "telnet `echo ${1##telnet://}|sed -e 's/:/ /'`"
>
> (which assumes $1 is properly formed).
>
> --Barry

Many thanks for your replies.

The good news is that I have gotten things to work.
The bad news is, that it's not a very elegant solution and that I
don't really fully understand what I'm doing.

I do have a basic understanding of sed(1). It's my understanding of
awk(1) that is sorely lacking.

My .telnet4firefox.sh file now is:

#!/bin/sh
xterm -e "telnet `echo ${*##telnet://} | sed 's/:/ /g'`"

- I understand the backtick quoted execution.
- I *think* the {} bit is awk(1), but I'm not entirely clear how it
does what it does.
- I think that the $* variable, which I think is somehow what the
${*##telnet://} bit is about, is the entire string of parameters
passed to the script. ($1 as in the previous examples would be the
first parameter only.)

I'm not really happy with the way this is put together. If awk(1) can
remove telnet:// from $* (if present), then surely it should be able
to turn a colon (if present) into a space, right?

Yes, this is an opportunity for me to really start looking into
awk(1), but thus far I seem to be making little headway...

Thanks again and kind regards,
--ropers

Reply via email to