1

What's the best command that allows me to do this:

  1. send the output of say ls to a file called etcdir
  2. Print out the etcdir file using cat
  3. Print out the exit status using echo $?
  4. Breaking up the command into two lines.

I know its something like

sudo ls > etcdir && cat etcdir ??? \ echo $?

or

sudo ls > etcdir && cat etcdir; \ echo $?

~thanks in advance

1 Answers1

2

You can combine step 1 and 2 by using tee which copies output to a file instead of redirecting it, so that it will still be visible in terminal.

Here would be your commands:

ls | tee etcdir
echo $?
Byte Commander
  • 107,489
  • If this answer solves your question, please accept it by clicking the grey check button on its left. Thanks and welcome to Ask Ubuntu. – Byte Commander Sep 10 '16 at 10:33