Re: Reintroducing fish, the friendly interactive shell



On 9 Mar 2006 05:17:32 -0800, liljencrantz@xxxxxxxxx wrote:
[...]
In zsh, RE's * is #, RE's + is ##, RE's ? is (...|) (or
nothing). That makes zsh patterns to involve fewer keystrokes.
That also means the grouping can be implemented as (...).
Note that zsh implemented globbing attributes (like case
insensitive, approximate matching, activation of backreference
the same way as perl does: (#...) in zsh, (?...) in perl,
because # can't otherwise follow a ( in zsh the same way as ?
can't otherwise follow a ( in perl.

Isn't this just a new syntax for regular expressions?

It is. It is also one that is compatible (mostly) with historical
globbing and is more suitable for matching filenames than the
standard REs.

Why not simply
use grep to provide you with real regexps?

grep doesn't do filename expansion, and basic REs are not handy
to match filenames.

The unix philosphy of using
a set of orthogonal commands that do one thing each, and connecting
them using pipes is very powerful. Globbing is a _very_ useful hack
that breaks this philsophy by allowing you to perform some types of
very _simple_ matchings inside the shell. The above seems to make
globbing into this huge, hairy beast that can be used for almost
anything find, grep, head, tail, ls and sort do, with a syntax that is
as readable as Perl. What is the point of stuffing all this stuff into
the shell that can be implemented in a more readable and even more
poerful way using external commands?

Maybe because with a few keystrokes, you can do more reliably
than you could have done in a 20 line unreadable script.

[...]
Also, at the prompt, you don't read what you type, it's
write-only. For scripts, zsh has longer forms that you might
consider more readable (like kshglob). Note that zsh also
supports perl regexp (with a builtin in a loadable module).

Why the fixation with avoiding external commands?

Yes, in that case, this doesn't make more sense. the pcre module
is sold as an "example module" though. It may come handy if you
don't have perl.

[...]
ls -S (find . -mmin -120)|head
(or ls -S `find . -mmin -120`|head if you haven't switched to fish yet)

ls -Sd and it doesn't select regular files (or symlinks to
regular file), and it makes the assumtion file paths don't have
newline or blank characters. And -S and -mmin are not Unix.

You use a pipeline containing find, ls and head. That's the beauty of
pipelines

But it's broken by design. Either Unix should prohibit all types
of non-alnum chars in filenames, or command substituion and all
the standard filtering utilities should be changed to be able to
cope with a NUL character separator (zsh is the only shell that
supports the NUL character (maybe fish does as well?)).

use one tool to solve each part of the task, and string them
together in a pipeline to solve a nearly infinite number of problems
with a small set of simple tools.

Yes, in theory it's nice. zsh gives you something more powerful
that doesn't use that framework. You're free to use grep and the
like with zsh. I made my choice ;).

Also notice that the find command is comparable in length to the zsh
version espacially if you use 'echo' to output it to stdout.
[...]

On a GNU system, the strict equivalent of zsh's would be:

eval "set -- $(find . -name '*.c' \( -type f -o -type l \) --exec \
find {} -follow -prune -type f -mmin -120 -printf '%s:\p\0' \; |
sort -rnz | awk -v'RS=\0' '
function escape(s) {
gsub(/'\''/, "'\''\\\'\'\''", s)
return "'\''" s "'\''"
}
{NR <= 10} {
sub(/[^:]*:/, "")
printf " %s", escape($0)
}')"

and there's no Unix equivalent.

Is that more readable or short or ortogonal?

It will probably not work with old versions of gawk.

--
Stephane
.



Relevant Pages

  • Re: Reintroducing fish, the friendly interactive shell
    ... #-based regexps zsh has better than regular regexps. ... See also the usage of zsh globbing combined with zmv (see ... syntax, and it doesn't even seem to be a better syntax. ... reports symlinks to regular files but also to non-regular files. ...
    (comp.unix.shell)
  • Re: Reintroducing fish, the friendly interactive shell
    ... ksh did it as: ... That makes zsh patterns to involve fewer keystrokes. ... Note that zsh implemented globbing attributes (like case ...
    (comp.unix.shell)
  • Re: Reintroducing fish, the friendly interactive shell
    ... That makes zsh patterns to involve fewer keystrokes. ... Note that zsh implemented globbing attributes (like case ... Isn't this just a new syntax for regular expressions? ...
    (comp.unix.shell)
  • Re: Reintroducing fish, the friendly interactive shell
    ... #-based regexps zsh has better than regular regexps. ... So use globbing for the easy things like *.html, ... but Unix barely exists anyway. ... Solaris, AIX and friends all extend standard ...
    (comp.unix.shell)
  • Re: delete lines useing sed
    ... >> Not work, it seems find does not interprets this expression, or ... There's no such thing like "extended globbing" anyway, ... different versions), zsh extended globbings, zsh ksh globbing ...
    (comp.unix.shell)