[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
newlines and $(...) processing
From: |
Bob Proulx |
Subject: |
newlines and $(...) processing |
Date: |
Sun, 13 May 2007 11:38:25 -0600 |
User-agent: |
Mutt/1.5.9i |
I was asked a question recently and I have not been able to deduce the
answer and so am appealing to the group for further education. I
could not find a match for my question in the FAQ.
$ printf "\n" | od -tx1
0000000 0a
$ printf "\n" | wc -c
1
But when this is used with a command substitution the newline
disappears.
$ printf "$(printf "\n")" | wc -c
0
Thinking that the IFS was reason for this I tried the following, where
the ' ' is a single space character.
$ export IFS=' '
$ printf "\n" | wc -c
1
$ printf "$(printf "\n")" | wc -c
0
Hmm... Shouldn't this last case have printed a single newline? The
IFS no longer contains a newline. Why wouldn't a literal 0x0a be
embedded into the "$(...)" command substitution string and then be
printed by printf? The following shows that a literal newline would
be printed in that case.
$ printf "
" | wc -c
1
$ printf "
> " | od -tx1
0000000 0a
I can tell that I am missing something basic in the understanding of
the behavior.
Thanks
Bob
- newlines and $(...) processing,
Bob Proulx <=