Re: Bash capital–non-capital substitution

Wes James comptekki at gmail.com
Mon Oct 28 15:49:21 UTC 2013


On Sat, Oct 26, 2013 at 6:53 AM, Johnny Rosenberg <gurus.knugum at gmail.com>wrote:

>
> x="hello"
> echo ${x} → hello
> echo ${x^} → Hello
> echo ${x^^} → HELLO
>
> So far, so good.
>
> x="HELLO"
> echo ${x} → HELLO
> echo ${x,} → hELLO
> echo ${x,,} → hello
>
> Still good.
>
> echo ${x^} → HELLO
> echo ${x^,} → HELLO
>
> Question: How to do ”HELLO” → ”Hello” in one step?
>
> I can do it in two steps, of course:
> y=${x,,}; echo ${y^} → Hello
>
>
> Johnny Rosenberg
>
>
It doesn't look like you can use ${} inside another ${} with bash.

I found these alternatives :

s="HELLO"
echo $s | sed 's/.*/\L&/; s/[a-z]*/\u&/g'
Hello

or use zsh.

s="HELLO"
echo ${(C)${(L)s}}
Hello

s="THIS IS A TEST"
echo ${(C)${(L)s}}
This Is A Test

-wes
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20131028/06e1dceb/attachment.html>


More information about the ubuntu-users mailing list