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*

11
  • interesting about the <<< temp file.. you can also write to "global" shell variables after using the shell options shopt -s lastpipe && set +m Commented Apr 10, 2022 at 22:27
  • @alchemy, I don't see how lastpipe would help. Even if you meant myfunction | IFS= read -rd '' var, myfunction would still run in a subshell. Commented Apr 11, 2022 at 6:46
  • those two options do actually allow changing shell variables: see my answer unix.stackexchange.com/a/698694/346155 Commented Apr 12, 2022 at 2:13
  • 1
    (1) +1, because complex_function > tmpfile; myvar=$(<tmpfile) is probably the best answer to the question for bash (with the caveat that you may need to use myvar=$(cat tmpfile) in some other shells). How on earth did nobody else suggest this in four months? (1b) I’m surprised that you didn’t even link to an answer explaining how to preserve multiple newlines at the end of a command substitution. … (Cont’d) Commented Apr 24, 2022 at 6:40
  • 1
    @ak2, I don't expect there be. Is suppose I hadn't realised =() also worked or possibly it didn't work in older versions. Commented Jul 17, 2023 at 9:27