Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: virtual files?



On Thu, Apr 21, 2016 at 12:12 AM, Emanuel Berg <embe8573@xxxxxxxxxxxxx>
wrote:

> "Benjamin R. Haskell" <zsh@xxxxxxxxxx> 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


Messages sorted by: Reverse Date, Date, Thread, Author