From: "Bart Schaefer" <schaefer@candle.brasslantern.com>
To: Clint Adams <schizo@debian.org>, zsh-users@sunsite.auc.dk
Subject: Re: more fun with parameter expansion
Date: Fri, 16 Jun 2000 14:44:30 -0700 [thread overview]
Message-ID: <000616144430.ZM4632@candle.brasslantern.com> (raw)
In-Reply-To: <000616140019.ZM4608@candle.brasslantern.com>
On Jun 16, 2:00pm, Bart Schaefer wrote:
> Subject: Re: more fun with parameter expansion
>
> for f in **/*(DNon); do
> mv -v $f ${${(M)f%/*}:+${${f%/*}:l:gs/ /_/}}${${${(M)f%/*}:-$f}:l:gs/ /_/}
> done
>
> The `(on)' (order by name) is probably unnecessary, and won't work in 3.0.x
> (though everything else should).
Of course I completely forgot that the whole reason I split the thing into
head and tail was because this needs to work in REVERSE name order. Sigh.
The correct solution is
for f in **/*(DNOn^M); do
mv -v $i ${${(M)i%/*}:+${i%/*}}${${${(M)i%/*}:-$i}:l:gs/ /_/}
done
(note one fewer :l:gs and turn *off* markdirs) which *won't* work in 3.0.x
because of no (On) glob flag.
> Writing that one-liner out a bit longer might make this more readable:
>
> t=${(M)f%/*} # The tail of the path, including leading slash
> h=${t:+${f%/*}} # The head of the path if the tail is non-empty
> t=${t:-$f} # The tail is the path when the tail is empty
>
> h=$h:l # Downcase the head, same as ${(L)h}
> h=$h:gs/ /_/
This was my error; don't modify the head, instead wait for it to become
the tail (that's why the reverse ordering) and then modify it.
> t=$t:l # Downcase the tail
> t=$h:gs/ /_/
And I forgot that braces are needed because of the space:
t=${t:gs/ /_/}
> mv $f $h$t
>
> The last five steps could be written as
>
> mv $f ${${:-$h$t}:l:gs/ /_/}
Rather:
mv $f $h${t:l:gs/ /_/}
which isn't nearly as mysterious. Oh well.
next prev parent reply other threads:[~2000-06-16 21:45 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-06-16 18:53 Clint Adams
2000-06-16 19:54 ` Clint Adams
2000-06-16 21:00 ` Bart Schaefer
2000-06-16 21:44 ` Bart Schaefer [this message]
2000-06-17 1:17 ` Clint Adams
2000-06-18 22:02 ` Peter Stephenson
2000-06-19 9:08 ` Peter Stephenson
2000-06-19 15:21 ` Clint Adams
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=000616144430.ZM4632@candle.brasslantern.com \
--to=schaefer@candle.brasslantern.com \
--cc=schizo@debian.org \
--cc=zsh-users@sunsite.auc.dk \
/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).