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*

3
  • 2
    For my purposes, this is the correct solution. I don't want the variable 'var' to pollute the environment as it does in the accepted answer. Commented Sep 13, 2017 at 15:12
  • If the simple subshell approach is "Portable (Bourne and POSIX)", why bother with all the more verbose answers for specific shells? Commented Aug 12, 2022 at 8:24
  • 1
    @Noumenon, because that approach has a side effect (runs in a subshell) that makes it unapplicable in man cases. Commented Aug 12, 2022 at 8:26