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

Re: changing case to Title Case [redux]



On Fri, Jun 18, 2021 at 11:20 PM TJ Luoma <luomat@xxxxxxxxx> wrote:
>
> > print -r -- ${${(L)foo}//(#b)((#s)|[[:space:]])([[:alpha:]])/$match[1]${(U)match[2]}}
>
> That works great in Terminal.app on my Mac, but I can't get it to work in a shell script:

Use of (#b)(#s) and $match needs extendedglob, which isn't enabled for "zsh -f".

BTW, the for-loop isn't needed, this is a one-liner except for the setopt:

#!/usr/bin/env zsh -f
setopt extendedglob
print -r -- ${${(L)@}//(#b)((#s)|[[:space:]])([[:alpha:]])/$match[1]${(U)match[2]}}

In the current development version, you can enable extendedglob for a
single parameter substitution with the (*) flag:

#!/usr/bin/env zsh -f
print -r -- ${(*)${(L)@}//(#b)((#s)|[[:space:]])([[:alpha:]])/$match[1]${(U)match[2]}}




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