-1

Is there a way to get the command that is being executed and the result of the command in the same output file?

i want a output file

command1 'some kind of delimiter' output 'New line'

command2 'some kind of delimiter' output 'New line'

command3 'some kind of delimiter' output 'New line'

is this possible ??? please guide me on achiving this ...

2
  • make a shell script (echo then command etc)? Commented Nov 6, 2014 at 7:18
  • The usual way of making an archive copy of commands run and their output is to use script. See man 1 script. It generates a log file that resembles the terminal interaction that you see. Commented Nov 6, 2014 at 8:18

1 Answer 1

0

I am not sure what your command is but here's the sample i have taken to be ls command just for illustration purpose.

ls script.sh >> temp; echo $(history | tail -2 | head -1 | awk '{print $2}' && cat temp) && rm -rf temp

What it does is:

command ls redirects output to a temp file (remember i don't know your command and ls is just a sample so you have output stored in temp file)

second command - just grabs your last command that you executed in this case it would be ls and output of the command that we stored

and finally you delete the file that you just created.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.