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.

Required fields*

7
  • 2
    If what you say is true, then I would be absolutely stunned. If there is a shopt to change your described default behaviour, then I'd be happy again... I find it difficult to think that Bash/Linux/Unix would pollute such a critical function as "capturing stdout" just because date doesn't have a with/without '\n' option... The obvious fix would be that bash (or other shell) has a shopt for this... Do you know of any? .. and do you have any reference links that speak of the whys and wherefores of this isssue? ... and why doesn't date have a \n option.. It should! Commented Jul 31, 2011 at 16:02
  • 3
    Command substitutions appeared in the first version of the Bourne shell in the "7th edition" of Unix in 1979. It was already a big revolution and I guess (I was not born) that nobody cared about keeping trailing '\n' or not. Yes, you can read the manpage in less than 10min, and it seems nothing has changed about command substitution until then. Except for the preferred $() alternative syntax. Commented Jul 31, 2011 at 17:01
  • 1
    Thanks.. I thought this may be a legacy issue, and it certainly is shaping up to the fact that I'd better start watching my Command Substitutions more carefully. Until today I must have been surviving on a wing an a prayer.. Some of those "mysterious happenings" I've encountered are starting to make sense now :) ... So in a reverse case of your "date" posit, if I want to keep my trailing \n, I must code something like this :( { echo -n "The current date is "; var="$(date; echo -e x)"; var="${var%x}"; echo -n "$var"; echo ", have a good day!"; } .. so be it :) Commented Jul 31, 2011 at 18:08
  • PS re my above comment: Of course, just date would work, but I just used date as an example of any command.. Commented Jul 31, 2011 at 18:39
  • Your 'question' about date was the strongest promt towards my understanding of 'why' Command Substution does what it does, so this has been the 'best' answer to my question... and I certainly also needed the other good answers as well.. Commented Jul 31, 2011 at 22:41