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.

3
  • Depending on your OS, var=$(ls | tee /proc/$$/fd/1) might work too. Commented Oct 26, 2011 at 12:40
  • Even if this is working perfectly, i post you an "do-it-yourself way" example. Im a Linux/bash noob, but i like learn those tips :D Commented Jan 21, 2015 at 8:13
  • Note that this (tee) only catches STDOUT output and that programs often do not color it (i.e. use VAR=$(ls --color | tee /dev/tty) to get coloured output). Commented Sep 28, 2017 at 14:07