[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Getting rid of white space with % and %%
From: |
Greg Wooledge |
Subject: |
Re: [Help-bash] Getting rid of white space with % and %% |
Date: |
Mon, 21 May 2012 17:23:46 -0400 |
User-agent: |
Mutt/1.4.2.3i |
On Mon, May 21, 2012 at 03:17:53PM -0600, 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:]]*}'"
It appears you are trying to trim all the trailing whitespace from a
string variable. You can do that with extended globs:
shopt -s extglob
echo "'${string%%+([[:space:]])}'"
Or if you don't want to use extended globs, you can do it two steps:
remove=${string##*[![:space:]]}
echo "'${string%$remove}'"
Normal globs (like the ones you were attempting to use) do not have a
full closure operator, so you can't say "0 or more spaces".