Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH?] Nofork and removing newlines



2024-03-05 14:48:00 -0800, Bart Schaefer:
[...]
> The suggested change would provide
> $(...)-like behavior for the usual case and a simple way to keep the
> newline(s) in the less-usual cases.
[...]

For reference, some other shells that can keep trailing newline
in command subtitution:

rc:

  whole_output = ``(){cmd and its args}

fish:

  set whole_output (cmd and its args | string collect -aN)

  (-aN short for --allow-empty --no-trim-newlines).

  fish's command substitution ( (...) and also $(...) including
  inside "..." in recent versions) doesn't fork so is closer to
  ksh93's ${ cmd; } than ksh86's $(...)

POSIX/Korn-like shells:

  I'm sure everyone will have their own variant, but

  get_whole_output() {
    eval "
      $1"'=$(shift; "$@"; ret=$?; echo .; exit "$ret")
      set -- "$1" "$?"
      '"$1"'=${'"$1"'%.}
      return "$2"'
  }
  get_whole_output whole_output cmd and its args

  (bearing in mind that there aren't many characters beside .
  that you can use safely there as it's important its encoding
  can't be found in the encoding of other characters.

-- 
Stephane




Messages sorted by: Reverse Date, Date, Thread, Author