more bash! regex substitution to crop trailing whitespaces

Kevin Cozens kevin-4dS5u2o1hCn3fQ9qLvQP4Q at public.gmane.org
Tue Dec 18 20:09:16 UTC 2007


Madison Kelly wrote:
>     # Leading spaces off of VAL
>     if [[ "$VAL" =~ '(\s+)(.*)' ]]; then
>     {
>         VAL=${BASH_REMATCH[2]};
>     }

You should consider changing the if statement to anchor the pattern match to 
the start of the string.

     if [[ "$VAL" =~ '^(\s+)(.*)' ]]; then

-- 
Cheers!

Kevin.

http://www.ve3syb.ca/           |"What are we going to do today, Borg?"
Owner of Elecraft K2 #2172      |"Same thing we always do, Pinkutus:
                                 |  Try to assimilate the world!"
#include <disclaimer/favourite> |              -Pinkutus & the Borg
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list