Skip to main content
added 134 characters in body
Source Link
Stéphane Chazelas
  • 584.7k
  • 96
  • 1.1k
  • 1.7k
LC_ALL=C IFS= read -rd '' output < <(cmd)

(LC_ALL=C needed to work around some bugs in some versions of bash).

IFS= read -rd '' output < <(cmd)
LC_ALL=C IFS= read -rd '' output < <(cmd)

(LC_ALL=C needed to work around some bugs in some versions of bash).

added 127 characters in body
Source Link
Stéphane Chazelas
  • 584.7k
  • 96
  • 1.1k
  • 1.7k

To get the exit status of cmd, you can do wait "$!"; ret=$? in some versions of bash but not in zsh though in zsh, you can write it cmd | IFS= read -rd '' output and get the exit status in $pipestatus[1].

To get the exit status of cmd, you can do wait "$!"; ret=$? in bash but not in zsh.

To get the exit status of cmd, you can do wait "$!"; ret=$? in some versions of bash but not in zsh though in zsh, you can write it cmd | IFS= read -rd '' output and get the exit status in $pipestatus[1].

added 243 characters in body
Source Link
Stéphane Chazelas
  • 584.7k
  • 96
  • 1.1k
  • 1.7k

An alternative is toSince version 3.4.0 (released in March 2022), you can do instead:

set output (cmd | string collect --allow-empty --no-trim-newlines)

With older versions, you could do:

Since versionWith the caveat that $output is an empty list instead of a list with one empty element if there's no output.

Version 3.4.0 (released in March 2022), fish also supportsadded support for $(...) which behaves like (...) except that it can also be used inside double quotes in which case it behaves like in the POSIX shell: the output is not split on lines but all trailing newline characters are removed.

An alternative is to do:

Since version 3.4.0 (released in March 2022), fish also supports $(...) which behaves like (...) except that it can also be used inside double quotes in which case it behaves like in the POSIX shell: the output is not split on lines but all trailing newline characters are removed.

Since version 3.4.0 (released in March 2022), you can do instead:

set output (cmd | string collect --allow-empty --no-trim-newlines)

With older versions, you could do:

With the caveat that $output is an empty list instead of a list with one empty element if there's no output.

Version 3.4.0 also added support for $(...) which behaves like (...) except that it can also be used inside double quotes in which case it behaves like in the POSIX shell: the output is not split on lines but all trailing newline characters are removed.

added 291 characters in body
Source Link
Stéphane Chazelas
  • 584.7k
  • 96
  • 1.1k
  • 1.7k
Loading
Loading
edited body
Source Link
user232326
user232326
Loading
deleted 1 character in body
Source Link
Stéphane Chazelas
  • 584.7k
  • 96
  • 1.1k
  • 1.7k
Loading
added 118 characters in body
Source Link
Stéphane Chazelas
  • 584.7k
  • 96
  • 1.1k
  • 1.7k
Loading
added 688 characters in body
Source Link
Stéphane Chazelas
  • 584.7k
  • 96
  • 1.1k
  • 1.7k
Loading
deleted 19 characters in body
Source Link
Stéphane Chazelas
  • 584.7k
  • 96
  • 1.1k
  • 1.7k
Loading
added 778 characters in body
Source Link
Stéphane Chazelas
  • 584.7k
  • 96
  • 1.1k
  • 1.7k
Loading
added 94 characters in body
Source Link
Stéphane Chazelas
  • 584.7k
  • 96
  • 1.1k
  • 1.7k
Loading
added 1526 characters in body
Source Link
Stéphane Chazelas
  • 584.7k
  • 96
  • 1.1k
  • 1.7k
Loading
Add missing word - "work"
Source Link
Tom Hale
  • 33.3k
  • 42
  • 163
  • 257
Loading
added 259 characters in body
Source Link
Stéphane Chazelas
  • 584.7k
  • 96
  • 1.1k
  • 1.7k
Loading
added 259 characters in body
Source Link
Stéphane Chazelas
  • 584.7k
  • 96
  • 1.1k
  • 1.7k
Loading
added 804 characters in body
Source Link
Stéphane Chazelas
  • 584.7k
  • 96
  • 1.1k
  • 1.7k
Loading
Source Link
Stéphane Chazelas
  • 584.7k
  • 96
  • 1.1k
  • 1.7k
Loading