Quantcast
Channel: Direct output from a command to a file including the original command, AND print in terminal - Ask Ubuntu
Viewing all articles
Browse latest Browse all 4

Direct output from a command to a file including the original command, AND print in terminal

$
0
0

When running some tests, I need to run a series of commands. It would be extremely useful to me, and save me a lot of time, if there was a way to do all of these things:

  • Run the command I need to run
  • Redirect all the output from the command to a specified file
  • Include the original command in the specified file
  • Print the output from the original command in the terminal

People have suggested using tee to me which does a great job of printing to terminal as well as sending to a file but doesn't include the original command. What I'd like to end up with is a file where the first line is the command I ran, and then below that is the output from the command.

Someone suggested this:

echo "ls -l" | xargs -I{} bash -c "echo >> output.file; eval {} >> output.file"

But this doesn't either print the output in the terminal or include the original command in the file.

I'd appreciate any ideas.


Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images