[NTLUG:Discuss] printing bash commands as output

Leroy Tennison leroy_tennison at prodigy.net
Sat Dec 8 11:22:10 CST 2007


Robert Citek wrote:
> On Dec 7, 2007 12:17 AM, Patrick R. Michaud <pmichaud at pobox.com> wrote:
>> On Fri, Dec 07, 2007 at 05:52:56AM +0000, Leroy Tennison wrote:
>>> There are situations where it would be nice to document a process and
>>> it's results, for example:
> ...
>>> If I redirect the output of a bash script containing the above command
>>> pipeline to a file it will contain the results but I won't know what
>>> produced the results (the command pipline doesn't end up in the output
>>> file).  Is there an easy way to get both?
>> In bash, try "set -x".  Then every command gets echoed as part of
>> the output (preceded by a '+').
> 
> set -x does indeed work great.  On trick I use is to put parentheses
> around the command sets.  For example:
> 
> ( set -x ; ls /etc/ ; date ; echo "Hello World" ) >& output.txt
> 
> The parentheses ensure that my interactive shell stays sane.
> 
> Another tool you might want to explore is script.  It captures
> everything you type and that is displayed on the screen to a text
> file.  'man script' for more details.
> 
> Good luck and let us know what worked for you.
> 
> Regards,
> - Robert
> 
> _______________________________________________
> http://www.ntlug.org/mailman/listinfo/discuss
> 
Thanks for the help.  The 'set -x' works find for my needs.



More information about the Discuss mailing list