help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Getting rid of white space with % and %%


From: Eric Blake
Subject: Re: [Help-bash] Getting rid of white space with % and %%
Date: Mon, 21 May 2012 15:25:10 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120430 Thunderbird/12.0.1

On 05/21/2012 03:17 PM, Bill Gradwohl wrote:
> I noticed it's apparently legit to say the following:
> 
> string='hello this  is   a    test     '
> echo "'${string}'" original
> 
> echo "'${string%[[:space:]]}'"
> echo "'${string%[[:space:]]*}'"
> echo "'${string%%[[:space:]]*}'"
> 
> Produces:
> address@hidden ycc# ./tst
> 'hello this  is   a    test     ' original
> 'hello this  is   a    test    '
> 'hello this  is   a    test    '
> 'hello'
> 
> I tried it with a tab character at the end of the string and that also
> works.
> 
> Is there any syntactically correct way to provide an * or + multiplier on
> to this to get rid of all the white space at the end of a line?

$ echo "'${string%${string##*[^[:space:]]}}'"

-- 
Eric Blake   address@hidden    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]