Re: zsh: alias oder function mit Parameter?

From: Oliver Fromme <olli(at)secnetix.de>
Date: Tue, 17 Jun 2003 21:21:41 +0200 (CEST)

Manfred Lotz <manfred.lotz(at)web.de> wrote:
> Ich habe nun versucht einen Alias zu definieren, der einen Parameter nimmt:
> alias lsd='ls -ld $1(/)'
>
> Das scheint nicht zu gehen.

Tut's auch nicht. Aliase sind ganz simple Geschöpfe.

> Dann habe ich es als function definiert:

Bessere Idee, das.

> lsd() { ls -ld $1(/) }
>
> Das Problem ist hier, dass bei z.B. lsd d* die Wildcard schon zu früh
> aufgelöst wird.
>
> Wie kann ich das lösen?

Mit 'nem Alias. In Kombination mit einer Funktion. :-)

Außerdem muß man mit dem GLOB_SUBST-Flag spielen. Das ist
jetzt schon zsh-Magie für Fortgeschrittene, aber so geht's:

$ lsd_func() { ls -ld ${~@}(/); }
$ alias lsd="noglob lsd_func"
$ lsd t* b*
drwxr-xr-x 2 olli olli 2560 Apr 28 01:47 bin
drwxr-xr-x 3 olli olli 512 Mar 25 2002 tex
drwxr-xr-x 5 olli olli 512 May 29 00:40 tmp
drwxr-xr-x 6 olli olli 512 May 30 21:21 txt
$

Wenn Dich interessiert, _warum_ es das tut, was es soll,
führe Dir die entsprechenden Manpages zu Gemüte. :-)

Gruß
   Olli

-- 
Oliver Fromme, secnetix GmbH & Co KG, Oettingenstr. 2, 80538 München
Any opinions expressed in this message may be personal to the author
and may not necessarily reflect the opinions of secnetix in any way.
"Clear perl code is better than unclear awk code; but NOTHING
comes close to unclear perl code"  (taken from comp.lang.awk FAQ)
To Unsubscribe: send mail to majordomo(at)de.FreeBSD.org
with "unsubscribe de-bsd-questions" in the body of the message
Received on Tue 17 Jun 2003 - 21:21:50 CEST

search this site