Una de shell scripting

View: New views
7 Messages — Rating Filter:   Alert me  

Una de shell scripting

by pclimentperez :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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.


--
To UNSUBSCRIBE, email to debian-user-catalan-REQUEST@...
with a subject of "unsubscribe". Trouble? Contact listmaster@...


Re: Una de shell scripting

by Roberto Torres-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/8/22 Pau Climent i Pérez <pclimentperez@...>:

> 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.
>
>
> --
> To UNSUBSCRIBE, email to debian-user-catalan-REQUEST@...
> with a subject of "unsubscribe". Trouble? Contact listmaster@...
>
>

Has de fer servir accents oberts per assignar el resultat a $M,
d'aquesta manera:

$ M=`echo $M | sed s/món/gent/`


--
To UNSUBSCRIBE, email to debian-user-catalan-REQUEST@...
with a subject of "unsubscribe". Trouble? Contact listmaster@...


Re: Una de shell scripting

by Salvador Muntané Sanegre :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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 debian-user-catalan-REQUEST@...
with a subject of "unsubscribe". Trouble? Contact listmaster@...


Re: Una de shell scripting

by Bugzilla from pere@nubiola.cat :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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: pere@...
          pnubiola@...
          pere.nubiola@...


2009/8/22 Salvador Muntane Sanegre <salvadormuntane@...>
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 debian-user-catalan-REQUEST@...
with a subject of "unsubscribe". Trouble? Contact listmaster@...



Re: Una de shell scripting

by pclimentperez :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

D'acord, GENIAL, accents oberts, gràcies!!

Pau.

El 22 / agost / 2009 01:13, Roberto Torres<black.death.1348@...>
va escriure:

> 2009/8/22 Pau Climent i Pérez <pclimentperez@...>:
>> 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.
>>
>>
>> --
>> To UNSUBSCRIBE, email to debian-user-catalan-REQUEST@...
>> with a subject of "unsubscribe". Trouble? Contact listmaster@...
>>
>>
>
> Has de fer servir accents oberts per assignar el resultat a $M,
> d'aquesta manera:
>
> $ M=`echo $M | sed s/món/gent/`
>
>
> --
> To UNSUBSCRIBE, email to debian-user-catalan-REQUEST@...
> with a subject of "unsubscribe". Trouble? Contact listmaster@...
>
>


--
To UNSUBSCRIBE, email to debian-user-catalan-REQUEST@...
with a subject of "unsubscribe". Trouble? Contact listmaster@...


Re: Una de shell scripting

by Ernest A.C. :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hola,

22/08/09 @ 14:16 (+0200), thus spake Pau Climent i Pérez:
> D'acord, GENIAL, accents oberts, gràcies!!

Si no tinc mal entès es recomana no utilitzar accents oberts
sinó $(....) que té el mateix efecte.

Ernest


--
To UNSUBSCRIBE, email to debian-user-catalan-REQUEST@...
with a subject of "unsubscribe". Trouble? Contact listmaster@...


Re: Una de shell scripting

by Jordi Funollet-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Saturday 22 August 2009 05:06:48 Pere Nubiola Radigales wrote:
> 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}

La tècnica de'n Pere té l'avantatge de que tot es fa dins d'un sol procés. En
canvi, la primera tècnica fa tres forks: un per l'echo, un altre pel sed, un
altre per executar tot això dins una subshell amb $().

En scripts petits no té importància; en scripts llargs que tenen això dins un
'for' i que s'executen cada hora, et pots tornar mico per adonar-te de què
provoca al teu servidor un pic de CPU 24 cops al dia.

--
##############################
### Jordi Funollet
### http://www.terraquis.net


--
To UNSUBSCRIBE, email to debian-user-catalan-REQUEST@...
with a subject of "unsubscribe". Trouble? Contact listmaster@...