How to extract sub-string on bash-shell

Mar 25, 2009 2 Replies

Hi everyone! First of all, I'm sorry for asking about bash-script.



I want to extract "3.4.4". I tried as follows.



/*Prompt*/ $arm-linux-gcc --version arm-linux-gcc (GCC) 3.4.4 Copyright (C) 2004 Free Software Foundation, Inc.



/*Shell Script*/ CROSS_GCC=arm-linux-gcc version=`$CROSS_GCC --version`



tmp=`expr "$version" : '\(.*(GCC) [0-9].[0-9].[0-9]\)'` tmp2=`expr "$version" : '\((GCC) [0-9].[0-9].[0-9]\)'`


echo $tmp echo $tmp2



/*Result of Shell Script*/ arm-linux-gcc (GCC) 3.4.4


On Wed, 25 Mar 2009 15:23:50 +0900, demiahn rearranged some electrons to say:

man awk

We'll assume you're also sorry about multi-posting instead of cross-posting. I already answered your question in another group.

Grant Edwards grante Yow! Jesus is my POSTMASTER at GENERAL ... visi.com

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required