zsh-users
 help / color / mirror / code / Atom feed
From: "Benjamin R. Haskell" <zsh@benizi.com>
To: Zsh-Users List <zsh-users@zsh.org>
Subject: Re: virtual files?
Date: Fri, 22 Apr 2016 01:55:02 -0400	[thread overview]
Message-ID: <CAB2RFrQqfqUXxQwg7ZMLmwGfj7LrzriVN-BcTvawXvu++VGF9w@mail.gmail.com> (raw)
In-Reply-To: <87zisneh10.fsf@student.uu.se>

[-- Attachment #1: Type: text/plain, Size: 2394 bytes --]

On Thu, Apr 21, 2016 at 12:12 AM, Emanuel Berg <embe8573@student.uu.se>
wrote:

> "Benjamin R. Haskell" <zsh@benizi.com> writes:
>
> > [...]
> >   () {
> >     local tmp=$1
> >     wget -q $link -O $tmp
> >     echo -n \$
> >     grep \"answer\" $tmp | cut -d \$ -f 2 | cut -d \< -f 1
> >   } =(:)
> > }
>
> [...]
>
> Only remark is, if you do all this trouble to get
> clean code, and then name the local "tmp", it is
> almost comical.


I like to think of it as a lingering code smell.  Don't need a tmp file
after all. ;-)


[...]


> >   awk '/"answer"/' |
>
> awk instead of grep in this context should be strange
> to many who are more familiar with grep, but grep has
> the problem that many like to put colorization to it
> which can screw up parsing. If the configuration
> is in an environmental, I suppose not even giving the
> full path to the binary to bypass an alias would get
> them away. One can supply a specification, of course,
> telling grep not to use colors, but rather than doing
> that, I switched to awk as you suggested.
>

I tend to prefer awk for a few reasons:
1. Whatever I wanted to `grep` usually needs some small amount of
post-processing. (not in this case, but usually scope expands.)
2. It's often one fewer pipe than a `grep ... | cut ...`
3. In a lot of contexts it's nice that it doesn't exit non-zero even if
nothing matches.
4. Its implementations tend to be very consistent (no worries about GNU vs
non-GNU or Linux/other that often arise with other utilities), so it's a
good command to learn.


I also changed the two cut:s for tr, and date +%Y from
> the `one` syntax form into $(another).
>

I strongly favor $(another) due to its nestability.


[...]


> One interesting thing is tho I changed three programs
> out of three used, I don't think this function is
> anything "remote" to the one I originally wrote.
> A small homage to the diversity of the Linux/Unix
> tools, I suppose. But come to think of it there are
> many players in the NHL that score some ~15 goals
> every season, but that doesn't mean they cannot also
> be completely different players, physical aspects as
> well as those of skill and style...
>

I noticed that I'd changed all the tools you used, too.  It's also fun to
notice that (maybe?) 5 years ago, I probably would've used Perl for the
whole pipeline, but these days I pretty rarely fall back to it.

-- 
Best,
Ben

      parent reply	other threads:[~2016-04-22  5:55 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-20  1:00 Emanuel Berg
2016-04-20  1:27 ` Nikolay Aleksandrovich Pavlov (ZyX)
2016-04-20  2:12   ` Emanuel Berg
2016-04-20  2:31     ` Nikolay Aleksandrovich Pavlov (ZyX)
2016-04-20  4:03     ` Bart Schaefer
2016-04-20  6:06       ` Emanuel Berg
2016-04-21 22:14       ` Emanuel Berg
2016-04-22  1:08         ` Bart Schaefer
2016-04-20  3:32 ` Benjamin R. Haskell
2016-04-20 20:34   ` Bart Schaefer
2016-04-22  5:26     ` Benjamin R. Haskell
2016-04-21  4:12   ` Emanuel Berg
2016-04-21  6:58     ` Bart Schaefer
2016-04-21  8:05       ` Emanuel Berg
2016-04-22  5:55     ` Benjamin R. Haskell [this message]

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=CAB2RFrQqfqUXxQwg7ZMLmwGfj7LrzriVN-BcTvawXvu++VGF9w@mail.gmail.com \
    --to=zsh@benizi.com \
    --cc=zsh-users@zsh.org \
    /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).