2010-12-02 26 views

Respuesta

12
$ foo=test.test.test 
$ echo "${foo//./}" 
testtesttest 
+0

como m nuevo en esto, puede u explicar un poco ... THX – rupali

+1

http://tldp.org/LDP/abs/html/parameter-substitution.html –

+1

funciona muy bien en conchas como Bourne. No tan bueno en tcsh '% tcsh -c 'foo = test.test.test; echo "$ {foo //./}" ' Missing} .'' – Johnsyweb

7

Una manera general sería tubo a sed:

sed -e 's/\.//g' 

En comando pedirá:

$ echo $hostname       // you type this 
test.test.test       // this is the result 
$ echo $hostname | sed -e 's/\.//g' 
testtesttest 
+0

okie ... thx ¿me puede decir qué hay sobre la sustitución de un \ char ???? – rupali

+0

@rupali: esto debería funcionar: 'sed-e 's/\\\ // g'' – darioo

+0

luego reemplazar el espacio será como - sed -e' s/\\ // g '¿es okie ??? – rupali

12

también puede canalizar en

tr -d '.' 

Pero la mejor manera de hacerlo es no utilizar un comando externo y usar el shell integrado.

4

No solo. pero - y _ así

HOSTNAME=test.test.test 
HOSTNAME=${HOSTNAME//[-._]/} # testtesttest 
+0

tuve que eliminar el último guión. – peteroak

Cuestiones relacionadas