From aharrison at gmail.com Mon Jul 7 22:44:17 2008 From: aharrison at gmail.com (Andy Harrison) Date: Mon, 7 Jul 2008 15:44:17 -0400 Subject: Completion question Message-ID: I'm just creating some completions for the 'smart' package manager. Using the smart install command for example, is it possible to make it so that anything after the 'install' pattern completes from one of the items in the list, regardless of the position of the pattern match? complete smart 'n/install/( --help --download --dump --explain --stepped --urls --yes )/' So instead of the redundancy of specifying word N: complete smart 'N/install/( --help --download --dump --explain --stepped --urls --yes )/' ...to match on the second to last word, that it can be anywhere after the pattern? Potentionally with the smart install command, you could have: smart install --explain --stepped --download --yes Additionally, in the list of possible completions, is it possible to include a list of words as well as a list of filenames matching a pattern like *.rpm? Just a snippet of what I did so far... complete smart n/install/'( --help --download --dump --explain --stepped --urls --yes )'/ \ c/--/'(help gui shell option ignore-locks)'/ \ c/-/'(o h)'/ \ C/*/'(update install reinstall upgrade remove check fix download clean search query info stats channel priority mirror flag config)'/ -- Andy Harrison public key: 0x67518262 From andrew at ugh.net.au Tue Jul 8 11:12:02 2008 From: andrew at ugh.net.au (Andrew) Date: Tue, 8 Jul 2008 09:12:02 +0100 Subject: Completion question In-Reply-To: References: Message-ID: <71045B01-ED99-400B-A351-D55CFDEB44AC@ugh.net.au> On 7 Jul 2008, at 20:44, Andy Harrison wrote: > Additionally, in the list of possible completions, is it possible to > include a list of words as well as a list of filenames matching a > pattern like *.rpm? I'm not aware of this being possible in an elegant fashion atm. I use a series of temporary variables and loops to make a completion line fro scp in my settings and it's not pretty. Hopefully I have missed something. Andrew From rocco at ntop.org Mon Jul 21 00:18:04 2008 From: rocco at ntop.org (Rocco Carbone) Date: Sun, 20 Jul 2008 23:18:04 +0200 Subject: pksh, the Packet Shell Message-ID: <18563.43916.129264.711752@tar.netikos.com> Hi all, I have made an extension to the tcsh to include network monitoring capabilities. The entire process of extending the shell is automatically performed via a shell script, that is responsible to download the tar-gzipped file from the Internet and apply on the fly all required modification to the tcsh's source code without any user intervention. One of my goals is to demonstrate how easy is using the extension built-ins mechanism the tcsh shell natively offers, and perhaps all the most common Unix shells already have, to implement a general purpose CLI for completely different application domains, being the network monitoring activities just an example. if someone is interested here are the url for tcsh deveopers: http://pksh.tecsiel.it http://pksh.tecsiel.it/shells.html http://pksh.tecsiel.it/hacking.html http://pksh.tecsiel.it/motivation.html http://pksh.tecsiel.it/history.html cheers /rocco -- Rocco Carbone mail-to: Pisa Italy Life is in the details In other words, you are welcome to use, share and improve me. You are forbidden to forbid anyone else to use, share and improve what I gave you. From msz at astrouw.edu.pl Mon Jul 28 14:48:16 2008 From: msz at astrouw.edu.pl (Michal Szymanski) Date: Mon, 28 Jul 2008 13:48:16 +0200 Subject: parsing lines with quotes Message-ID: <20080728114816.GA4961@astrouw.edu.pl> Hello, I wonder if there is any way to parse, using tcsh, lines from a external file, containing double quotes in such a way that the entire strings contained within the quotes are interpreted by the shell as single words. Say, I have a file like: a b c "gnus and armadillos" 1 "zebras and hienas" 2 Now, I want to process it in foreach line ( "`cat file`" ) # to get it line-by-line ... end being able to get the content of the first line as four words: "a" "b" "c" "gnus and armadillos" and the second as three words: "1" "zebras and hienas" "2" All my attempts using set ll=( $line ) set ll=( `echo $line` ) set ll=( `echo "$line"` ) etc. has failed resulting in the double quote appearing just as an ordinary character starting or ending the single word (like '"gnus' or 'hienas"' for example) I know I can write my own C-program parsing the line to output quoted strings as a single word but maybe there is a simpler way to do it, just using the "tcsh" features (or, maybe, a standard unix system command) for parsing the input. Thanks in advance for any hints, regards, Michal. -- Michal Szymanski (msz at astrouw dot edu dot pl) Warsaw University Observatory, Warszawa, POLAND From per at hedeland.org Mon Jul 28 15:57:05 2008 From: per at hedeland.org (Per Hedeland) Date: Mon, 28 Jul 2008 14:57:05 +0200 (CEST) Subject: parsing lines with quotes In-Reply-To: <20080728114816.GA4961@astrouw.edu.pl> Message-ID: <200807281257.m6SCv5r8065763@pluto.hedeland.org> Michal Szymanski wrote: > >All my attempts using > >set ll=( $line ) >set ll=( `echo $line` ) >set ll=( `echo "$line"` ) >etc. > >has failed OK, despite my promise in the previous message I just had to try it again - and it works. What you want is: eval set ll = "( $line )" (other quoting schemes are possible, but that seemed to be the simplest one). --Per PS The crash I got might be worthy of a fix, since on closer investigation (where tcsh doesn't bring my xterm down with it:-), it doesn't really seem to be specific to "advanced use of 'eval'": mars 10> tcsh mars 1> set line = 'a b c "gnus and armadillos"' mars 2> eval set ll = "$line" set: Variable name must begin with a letter. Abort (core dumped) mars 11> echo $version tcsh 6.15.01 (Astron) 2007-09-28 (i386-intel-FreeBSD) options wide,nls,dl,al,kan,rh,color,filec From per at hedeland.org Mon Jul 28 15:30:28 2008 From: per at hedeland.org (Per Hedeland) Date: Mon, 28 Jul 2008 14:30:28 +0200 (CEST) Subject: parsing lines with quotes In-Reply-To: <20080728114816.GA4961@astrouw.edu.pl> Message-ID: <200807281230.m6SCUSPI065173@pluto.hedeland.org> Michal Szymanski wrote: > >I wonder if there is any way to parse, using tcsh, lines from a external >file, containing double quotes in such a way that the entire strings >contained within the quotes are interpreted by the shell as single words. > >Say, I have a file like: > >a b c "gnus and armadillos" >1 "zebras and hienas" 2 > >Now, I want to process it in > >foreach line ( "`cat file`" ) # to get it line-by-line >... >end > >being able to get the content of the first line as four words: >"a" "b" "c" "gnus and armadillos" >and the second as three words: >"1" "zebras and hienas" "2" > >All my attempts using > >set ll=( $line ) >set ll=( `echo $line` ) >set ll=( `echo "$line"` ) >etc. > >has failed resulting in the double quote appearing just as an ordinary >character starting or ending the single word (like '"gnus' or 'hienas"' >for example) > >I know I can write my own C-program parsing the line to output quoted >strings as a single word but maybe there is a simpler way to do it, just >using the "tcsh" features (or, maybe, a standard unix system command) >for parsing the input. Well, there is this "standard unix system command" called 'sh': $ cat /tmp/xxx a b c "gnus and armadillos" 1 "zebras and hienas" 2 $ while read line; do > eval set -- "$line" > echo "====" > for w; do echo $w; done > done < /tmp/xxx ==== a b c gnus and armadillos ==== 1 zebras and hienas 2 (Ducking for cover.:-) Honestly, why anyone would try advanced scripting with *csh is beyond me, there are so many other ways to waste your time, most of them far less painful:-) - but maybe you have your reasons (and of course tcsh is the best shell for interactive use:-). Anyway, obviously 'eval' is the "ticket" here, tcsh has it too, and maybe you can get it to do what you want - when I tried, my tcsh crashed, so I won't attempt it again. --Per Hedeland From msz at astrouw.edu.pl Mon Jul 28 16:32:50 2008 From: msz at astrouw.edu.pl (Michal Szymanski) Date: Mon, 28 Jul 2008 15:32:50 +0200 Subject: parsing lines with quotes In-Reply-To: <200807281257.m6SCv5r8065763@pluto.hedeland.org> References: <20080728114816.GA4961@astrouw.edu.pl> <200807281257.m6SCv5r8065763@pluto.hedeland.org> Message-ID: <20080728133250.GA14107@astrouw.edu.pl> Thanks a lot, Per, I really appreciate your help (and equally your failure to keep your promise :)) I know that (ba)sh is much better for scripting and I even try to write the new scripts in it. Still, I know the *csh syntax much better than the Bournish so sometimes I am too lazy to RTFM and I start again in *csh. Also, I have many tcsh scripts that I edit for new applications, too complicated to translate into Bourne. Thanks again, Michal. On Mon, Jul 28, 2008 at 02:57:05PM +0200, Per Hedeland wrote: > Michal Szymanski wrote: > > > >All my attempts using > > > >set ll=( $line ) > >set ll=( `echo $line` ) > >set ll=( `echo "$line"` ) > >etc. > > > >has failed > > OK, despite my promise in the previous message I just had to try it > again - and it works. What you want is: > > eval set ll = "( $line )" > > (other quoting schemes are possible, but that seemed to be the simplest > one). > > --Per > -- Michal Szymanski (msz at astrouw dot edu dot pl) Warsaw University Observatory, Warszawa, POLAND From christos at zoulas.com Mon Jul 28 18:13:05 2008 From: christos at zoulas.com (Christos Zoulas) Date: Mon, 28 Jul 2008 11:13:05 -0400 Subject: parsing lines with quotes In-Reply-To: <20080728114816.GA4961@astrouw.edu.pl> from Michal Szymanski (Jul 28, 1:48pm) Message-ID: <20080728151305.ECA525654F@rebar.astron.com> On Jul 28, 1:48pm, msz at astrouw.edu.pl (Michal Szymanski) wrote: -- Subject: parsing lines with quotes | Hello, | | I wonder if there is any way to parse, using tcsh, lines from a external | file, containing double quotes in such a way that the entire strings | contained within the quotes are interpreted by the shell as single words. | | Say, I have a file like: | | a b c "gnus and armadillos" | 1 "zebras and hienas" 2 | | Now, I want to process it in | | foreach line ( "`cat file`" ) # to get it line-by-line | ... | end | | being able to get the content of the first line as four words: | "a" "b" "c" "gnus and armadillos" | and the second as three words: | "1" "zebras and hienas" "2" | | All my attempts using | | set ll=( $line ) | set ll=( `echo $line` ) | set ll=( `echo "$line"` ) | etc. | | has failed resulting in the double quote appearing just as an ordinary | character starting or ending the single word (like '"gnus' or 'hienas"' | for example) | | I know I can write my own C-program parsing the line to output quoted | strings as a single word but maybe there is a simpler way to do it, just | using the "tcsh" features (or, maybe, a standard unix system command) | for parsing the input. | | Thanks in advance for any hints, | | regards, Michal. Use a real shell for scripting :-) #!/bin/sh while read foo do eval set -- $foo echo line: for i do echo $i done done << \_EOF a "b c" d e f g h i j _EOF From christos at zoulas.com Mon Jul 28 18:19:15 2008 From: christos at zoulas.com (Christos Zoulas) Date: Mon, 28 Jul 2008 11:19:15 -0400 Subject: parsing lines with quotes In-Reply-To: <200807281257.m6SCv5r8065763@pluto.hedeland.org> from Per Hedeland (Jul 28, 2:57pm) Message-ID: <20080728151915.B89815654E@rebar.astron.com> On Jul 28, 2:57pm, per at hedeland.org (Per Hedeland) wrote: -- Subject: Re: parsing lines with quotes | Michal Szymanski wrote: | > | >All my attempts using | > | >set ll=( $line ) | >set ll=( `echo $line` ) | >set ll=( `echo "$line"` ) | >etc. | > | >has failed | | OK, despite my promise in the previous message I just had to try it | again - and it works. What you want is: | | eval set ll = "( $line )" | | (other quoting schemes are possible, but that seemed to be the simplest | one). | | --Per | | PS The crash I got might be worthy of a fix, since on closer | investigation (where tcsh doesn't bring my xterm down with it:-), it | doesn't really seem to be specific to "advanced use of 'eval'": | | mars 10> tcsh | mars 1> set line = 'a b c "gnus and armadillos"' | mars 2> eval set ll = "$line" | set: Variable name must begin with a letter. | Abort (core dumped) | mars 11> echo $version | tcsh 6.15.01 (Astron) 2007-09-28 (i386-intel-FreeBSD) options wide,nls,dl,al,kan,rh,color,filec Thanks, Per! christos Index: sh.func.c =================================================================== RCS file: /p/tcsh/cvsroot/tcsh/sh.func.c,v retrieving revision 3.145 diff -u -u -r3.145 sh.func.c --- sh.func.c 19 Sep 2007 20:28:07 -0000 3.145 +++ sh.func.c 28 Jul 2008 15:18:40 -0000 @@ -2287,11 +2287,11 @@ process(0); } - if (my_reenter == 0) + if (my_reenter == 0) { cleanup_until(&state); - - if (gv) - cleanup_until(gv); + if (gv) + cleanup_until(gv); + } resexit(osetexit); if (my_reenter)