Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • @Philomath: Both x="hello  " and x="hello     " will lose all their trailing spaces if the are displayed via echo $x... However only the very last newline of the Command Substituton is lost. Commented Jul 31, 2011 at 14:14
  • strange, I don't see any difference in my bash (verifying with xxd) Commented Jul 31, 2011 at 14:25
  • I just checke on this... It does remove all trailing newlines... I was experimenting with IFS when I got that impression, so let's cancel that one :).. but the question still remains... It is an fundamental part word splitting to condense multiple spaces to a single space, and to totally remove leading and trailing whitespace.. I can understand that, but I certainly don't understand why, with Command Substitution, it only strips \n and not all whitespace (as with word splitting), and why only the trailing end?.. and above all: "Command Substitution" is only partially substituting.. Why? Commented Jul 31, 2011 at 14:49
  • 5
    IFS has nothing to do with stripping newlines at the end of command substitutions. Commented Jul 31, 2011 at 21:09