zsh-workers
 help / color / mirror / code / Atom feed
From: DervishD <raul@pleyades.net>
To: Oliver Kiddle <okiddle@yahoo.co.uk>
Cc: Zsh <zsh-workers@sunsite.dk>
Subject: Re: Can Zsh do this for me?
Date: Tue, 2 Sep 2003 21:21:02 +0200	[thread overview]
Message-ID: <20030902192102.GB94@DervishD> (raw)
In-Reply-To: <2298.1062505554@gmcs3.local>

    Hi Oliver :)

 * Oliver Kiddle <okiddle@yahoo.co.uk> 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/


  reply	other threads:[~2003-09-02 19:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-09-02 12:08 DervishD
2003-09-02 12:25 ` Oliver Kiddle
2003-09-02 19:21   ` DervishD [this message]
2003-09-02 12:38 ` Alexey Tourbin
2003-09-02 13:07   ` Peter Stephenson
2003-09-02 19:22   ` DervishD
2003-09-02 13:30 ` Jason Price
2003-09-02 19:57   ` DervishD

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030902192102.GB94@DervishD \
    --to=raul@pleyades.net \
    --cc=okiddle@yahoo.co.uk \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).