+3  A: 

Yes, you can use:

history -w filename.sh

This will save your command history to filename.sh. You may need to edit that to keep just the lines at the end that are part of your command sequence.

NOTE: This is a bash command and will not work with all shells.

Amardeep
+1, it won't work in *any* shell, but I doubt there's a general solution to the problem.
Carl Norum
You can also use 'fc -l' (optionally with a range of command numbers) in both bash and ksh, which widens the scope slightly.
Jonathan Leffler
This page have a port of the idea to IRB:http://blog.nicksieger.com/articles/2006/04/23/tweaking-irb
El_Hoy
+1  A: 

script may help here. Typing script will throw you into a new shell and save all input and output to a file called typescript. When you're done with your interaction, exit the shell. The file typescript is then amenable to grep'ing. For example, you might grep for your prompt and save the output to the file. If you're a clumsy typist like me, then you may need to do some cleanup work to remove backspaces. There used to be a program that did thisbut I don't seem to find it right now. Here is one I found on the 'net: http://www.cat.pdx.edu/tutors/files/fixts.cpp

This approach is especially useful if you want to track and post on the web an entire interactive session.

Larry Morell
Thanks for that answer, it sound interesting and usefull, but not to write the script actuallly (because you have to grep the file, with *history* is more simple...)
El_Hoy