Jo personalment prefereixo fer servir
M=$(echo|sed s/món/gent/)
Els accents oberts es veuen poc
Ara bash permet simplificar lo anterior
proba M=${M/món/gent}
${parameter/pattern/string}
The pattern is expanded to produce a pattern just as in
pathname expan‐
sion. Parameter is expanded and the longest match of
pattern against
its value is replaced with string. If Ipattern begins
with /, all
matches of pattern are replaced with string. Normally only
the first
match is replaced. If pattern begins with #, it must
match at the
beginning of the expanded value of parameter. If pattern
begins with %,
it must match at the end of the expanded value of parameter.
If string
is null, matches of pattern are deleted and the / following
pattern may
be omitted. If parameter is @ or *, the substitution
operation is
applied to each positional parameter in turn, and the
expansion is the
resultant list. If parameter is an array variable subscripted
with @ or
*, the substitution operation is applied to each member of the
array in
turn, and the expansion is the resultant list.
Pere Nubiola Radigales
Telf: +34 656316974
e-mail: [email protected]
[email protected]
[email protected]
2009/8/22 Salvador Muntane Sanegre <[email protected]>
> El ds 22 de 08 de 2009 a les 00:44 +0200, en/na Pau Climent i Pérez va
> escriure:
> > Vinga valents:
> >
> > Imaginem que declarem una variable M:
> >
> > $ M="hola món"
> >
> > $ echo $M
> >
> > hello world
> >
> > Ara tenim M declarada, i volem eliminar-li les aparicions de "món" per
> > afegir-hi, posem per exemple "gent".
> >
> > Com faríeu això?
> >
> > Jo pensava fer servir sed:
> >
> > $ echo $M | sed s/món/gent/
> >
> > però ara com assigne el resultat a la variable M?
> >
> > M'explique?
> >
> > Pau.
> >
> >
>
> Hola Pau,
>
> No si vols dir això:
>
> export M=`echo $M | sed s/món/gent/`
>
> Salut
>
> Vado
>
>
> --
> To UNSUBSCRIBE, email to [email protected]
> with a subject of "unsubscribe". Trouble? Contact
> [email protected]
>
>