[gull] Shell - comment obtenir une partie du contenu d'une variable ?
Félix Hauri
felix at f-hauri.ch
Wed Jul 16 17:49:01 CEST 2003
On Wed, 16 Jul 2003, Daniel Cordey wrote:
> On Wednesday 16 July 2003 16:56, B . Carrupt wrote:
>
> > un.deux.trois ---> un.deux
> > quatre.cinq.six ---> quatre.cinq
>
> x='un.deux.trois'
> y='quatre.cinq.six'
>
> echo ${x%%.trois}
> un.deux
>
> echo ${y%%.six}
> quatre.cinq
>
> echo ${x##un.}
> deux.trois
>
> Mais bon, c'est assez limite...
Pourquoi deux ``#'' ou ``%''?
Si:
$ x=un.deux.trois.quatre
$ y=quatre.cinq.six
Alors:
$ echo ${x%%.*}
un
$ echo ${y%%.*}
quatre
$ echo ${x%.*}
un.deux.trois
$ echo ${y%.*}
quatre.cinq
$ echo ${x%.*.*}
un.deux
$ echo ${y%.*.*}
quatre
$ echo ${x##*.}
quatre
$ echo ${y##*.}
six
$ echo ${x#*.}
deux.trois.quatre
$ echo ${y#*.}
cinq.six
$ echo ${x#*.*.}
trois.quatre
$ echo ${y#*.*.}
six
Limité, mais sympa et efficace quand-même.
--
Félix Hauri - <felix at f-hauri.ch> - http://www.f-hauri.ch
More information about the gull
mailing list