Unexpected bash assignment result using tr command
Pregunta
This is the bash
statement in question:
xx="$(echo 'a_b' | tr '_' '\t')"
Why is the underscore replaced with a space instead of a tab?
Solución
It's not. :-)
If you check the result with echo $xx
, the tab will be replaced with a space.
Try echo "$xx"
(with double-quotes) instead.
Otros consejos
Not directly answering your question, but you can do this in pure Bash:
xx='a_b'
xx="${xx//_/ }"
(where the space in / }
is a literal Tab; you may need to use ^v
to enter it)
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow