Access Keys:
Skip to content (Access Key - 0)

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.

IS&T Contributions

Documentation and information provided by IS&T staff members

Last Modified:

February 25, 2009

Get Help

Request help
from the Help Desk
Report a security incident
to the Security Team
olc-unix olc-unix Delete
input input Delete
output output Delete
shell shell Delete
command command Delete
script script Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
This product/service is:
Easy to use
Difficult to use

This article is:
Adaptavist Theme Builder (4.2.3) Powered by Atlassian Confluence 3.5.13, the Enterprise Wiki