How can I capture both the input and output of a shell script?
You can do this by telling the shell to enter "verbose" mode, in which it will echo both the command typed and its output to "standard output".
The method varies slightly depending on which shell you're using.
Shell | Enable verbose mode | Disable verbose mode |
---|---|---|
tcsh | set verbose | unset verbose |
bash | set -v | set +v |
Once verbose mode is enabled, commands you type will be echoed before they are processed. You can redirect this output to a file using the ">" character, for example:
command > myfile.txt
Once you have captured the output you want, you can disable verbose mode using the appropriate command above.
You may also wish to use the "script" command, which can generate a transcript of a portion of your session. See "How can I save a copy of my program's output?" for more information.