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

changing case to Title Case [redux]



I just came across this 2012 post (https://www.zsh.org/mla/users/2012/msg00399.html) where I was asking about titlecase:


> On Mon, 14 May 2012 15:30:49 -0400
> TJ Luoma <luomat@xxxxxxxxx> wrote:
> > $ foo="ONE TWO thRee FoUR"
> > $ print -r -- "${(C)foo}"
> >
> > will output this:
> >
> > One Two Three Four
> >
> > but this:
> >
> > $ foo="ONE TWO thRee FoUR's"
> > $ print -r -- "${(C)foo}"
> >
> >
> >
> > will give this:
> >
> > One Two Three Four'S
> >
> > Note the S is capitalized
>
> If you like squiggles, you could do this:
>
> 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:

{begin script}
#!/usr/bin/env zsh -f

for i in "$@"
do

	print -r -- ${${(L)i}//(#b)((#s)|[[:space:]])([[:alpha:]])/$match[1]${(U)match[2]}}

done

exit 0
{end script}

For some reason, that not seem to do anything to the input.

What am I missing? Is there some Zsh feature that I need to enable to make this work in a script?

Thanks!

~ Tj





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