On Mon, 12 Nov 2007 00:25:29 +0100, ropers <[EMAIL PROTECTED]> wrote:
xterm -e "telnet `echo ${1##telnet://}|sed -e 's/:/ /'`"
...
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.
The ${var##string} part is ksh or bash specific, see "Parameter Expansion" in the bash man page if you're using bash. I see your #! line says /bin/sh but to my knowledge a "real" sh, not emulated by bash or ksh doesn't support ${##} and friends, if I'm wrong feel free to correct me. =) What it does is cut away the string "telnet://" from the beginning of the first positional parameter. (You've changed that to * in your last example, don't know what will be substituted for $* there if you have more than one positional argument for your script, you might what to test that or change back to ${1} ).
- 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.)
Yes. $@ is also all the positional parameters, they expand differently when expanded inside "". A full explaination can be found under "Special Parameters" in the bash man page.
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?
If I'd use a pipe, I'd pipe it to tr, not sed. But I wouldn't, I'd let bash do it: #!/bin/bash IFS=: set -- $1 host=${2##//} port=$3 xterm -e "telnet $host $port" This way, you won't need to use anything else than bash itself. =) What it does is that it splits $1 using : as a delimiter and stores the split parts into the positional arguments like this: $1 = "telnet" $2 = "//example.com" $3 = "1991" Then the host=${2##//} cuts away the "//" from $2 and stores in $host.
Yes, this is an opportunity for me to really start looking into awk(1), but thus far I seem to be making little headway...
Awk is nice, but this isn't awk. ;)
Thanks again and kind regards, --ropers
Hope it helps! / Linus -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/