From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2199 invoked from network); 2 Sep 2003 19:55:43 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 2 Sep 2003 19:55:43 -0000 Received: (qmail 22667 invoked by alias); 2 Sep 2003 19:55:22 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 19013 Received: (qmail 22607 invoked from network); 2 Sep 2003 19:55:21 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 2 Sep 2003 19:55:21 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [217.174.194.138] by sunsite.dk (MessageWall 1.0.8) with SMTP; 2 Sep 2003 19:55:21 -0000 Received: from DervishD.pleyades.net (212.Red-80-35-44.pooles.rima-tde.net [80.35.44.212]) by madrid10.amenworld.com (8.10.2/8.10.2) with ESMTP id h82JtIV15691; Tue, 2 Sep 2003 21:55:18 +0200 Received: from raul@pleyades.net by DervishD.pleyades.net with local (Exim MTA 2.05) id <19uGi6-00001d-00>; Tue, 2 Sep 2003 21:21:02 +0200 Date: Tue, 2 Sep 2003 21:21:02 +0200 From: DervishD To: Oliver Kiddle Cc: Zsh Subject: Re: Can Zsh do this for me? Message-ID: <20030902192102.GB94@DervishD> Mail-Followup-To: Oliver Kiddle , Zsh References: <20030902120846.GA1636@DervishD> <2298.1062505554@gmcs3.local> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <2298.1062505554@gmcs3.local> User-Agent: Mutt/1.4i Organization: Pleyades User-Agent: Mutt/1.4i Hi Oliver :) * Oliver Kiddle dixit: > > Right know, it can be written like this: > > ps xh | grep name | tr -s " " | cut -d " " -f 2 > This doesn't seem to work for PIDs >= 10000 where there is no initial > space in the ps listing. Oh, yes, you're true, it was just a quick hack, not a good work ;)) The point was the four processes neeced for this, and your answer below. Thanks a lot!! > > get the process ID using the command name, or if I can write the > > above pipeline in a shorter form using some Zsh capability. > You can write the command-line as: > ${${${(M)${(f)"$(ps xh)"}:#*$name*}## #}%% *} > (M) and :# does the grep. ## # removes initial space and the %% * does > the job of cut. > Use $~name if you'd like to use patterns for name. And if you only want > one PID, use [1] on the end of it all. That's great! A very good example of what I was looking for: the power of Zsh to do things faster ;)))) Right now I don't understand the entire line (but I'm new to expansions...), but I will take a look at the manual. Thanks a lot, truly :) > > BTW, I want to write a 'ps' command on my own because I don't > > like the procps one available for Linux, nor the others out there, > > and I think that with the zsh/stat module I could do it in a shell > > script :))) > I'm not quite sure how you'd do that using zsh/stat (using /proc?) but > good luck with it. The point is to examine /proc. Some of the things can be done using 'cat' and the like, but a couple of them must be done with the stat syscall, and maybe zsh/mapfile to read the file contents in an easy way. Really, Zsh is just incredible :) Raúl Núñez de Arenas Coronado -- Linux Registered User 88736 http://www.pleyades.net & http://raul.pleyades.net/