[NCLUG] bash question

Tkil tkil at scrye.com
Fri Apr 27 21:01:44 MDT 2007


>>>>> "WT" == Warren Turkal <wt at penguintechs.org> writes:

WT> Can anyone explain why the following doesn't result in a newline
WT> (0x0a) being piped to od?

WT> wt at pyrus:~/test/ctest$ echo -n "$(echo -ne "\n")" | od -t x1 -t a
WT> 0000000


WT> The following works as expected:

WT> wt at pyrus:~/test/ctest$ echo -n "
WT> " | od -t x1 -t a
WT> 0000000 0a
WT>          nl
WT> 0000001

WT> Is this a bug in bash or am I just doing something silly?

Not directly answering your question, but I will say that this sort of
requirement (precise control of whitespace / line endings etc) is one
of the many flags that will get me to stop writing a script in
sh/bash, and start writing it in perl.  :)

I'm assuming that you are simplifying some other script, but when
intricacies of quoting come up, I usually just reach for a more
coherent control language (in this case, perl).

It also has the advantage that perl is the same across many OSes,
while the details of "echo" etc tend to vary quite a bit more.

Anyway.  Good luck,
t.



More information about the NCLUG mailing list