Re: Bash capital–non-capital substitution

Johnny Rosenberg gurus.knugum at gmail.com
Mon Oct 28 17:20:39 UTC 2013


2013/10/28 Wes James <comptekki at gmail.com>

>
>
>
> 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 :
>

I see now that I wasn't clear enough in my question. Sorry for that. I
forgot to mention that my question was about built in Bash features only.
Maybe I should file a suggestion to the Bash developers. I would have
expected that echo ”${x^,}” → ”Hello”, but it didn't. Maybe I could ask the
developers to add this behaviour.

Thanks anyway!


Johnny Rosenberg


>
> 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
>
> --
> ubuntu-users mailing list
> ubuntu-users at lists.ubuntu.com
> Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20131028/46da342b/attachment.html>


More information about the ubuntu-users mailing list