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

Re: ls -l *(/)...



# lists@xxxxxxxxx / 2015-06-22 21:26:36 +0200:
> Am 22.06.2015 um 21:08 schrieb Marc Chantreux:
> >> Of course you can also iterate over them:
> >> for f in */*; echo $(basename $f) 
> > 
> > print -l */*:t 
> 
> Thanks, but I just intended the for-loop as a small one-line example :).
> Because I thought that the original intention might have been something
> along the lines of
> 
> for f in `ls */*`; ...

that's actually an antipattern.  first, the largely inconsequential
things: it forks an extra shell (and ls), and it's longer than

  for f in */*; ...

second, and this is the dealbreaker, pathnames with IFS characters in
them are going to break this code horribly.

% touch foo bar omg\ wtf
% for f in *; do print $f; done
bar
foo
omg wtf
% for f in `ls *`; do print $f; done 
bar
foo
omg
wtf

> I write longer zsh-scripts so seldom that I always forget what all
> those magic letters are for. So I need either a lengthy comment or I
> always have to read zsh manpages when I happen to stumble of the piece
> in question again.

the absolutee basics are quite easy to remember:

:t - tail
:h - head
:r - root
:a - absolute path
:A - absolute path, the grown-up version (uses realpath(3))

-- 
roman



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