[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: newlines and $(...) processing
From: |
Bob Proulx |
Subject: |
Re: newlines and $(...) processing |
Date: |
Sun, 13 May 2007 12:44:27 -0600 |
User-agent: |
Mutt/1.5.9i |
Andreas Schwab wrote:
> bob@proulx.com (Bob Proulx) writes:
> > But when this is used with a command substitution the newline
> > disappears.
>
> Command substitution always strips trailing newlines.
Here is the part that I have previously missed:
man bash
Command Substitution
...
Bash performs the expansion by executing command and replacing
the command substitution with the standard output of the
command, with any trailing newlines deleted. Embedded newlines
are not deleted, but they may be removed during word splitting.
And this follows POSIX:
http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_03
The shell shall expand the command substitution by executing command
in a subshell environment (see Shell Execution Environment) and
replacing the command substitution (the text of command plus the
enclosing "$()" or backquotes) with the standard output of the
command, removing sequences of one or more <newline>s at the end of
the substitution.
I somehow missed this when I was researching it previously.
Thanks!
Bob