开发者

Can I use what I wrote on the shell (bash, cmd, irb, etc) in a script automatically?

The general idea is pretty simple, I want to make a script for a certain task, I do it in the shell (any shell), an开发者_如何学Pythond then I want to copy the commands I have used.

If I copy all the stuff in the window, then I have a lot of stuff to delete and to correct. (and is not easy to copy from shell)

Resume: I want to take all the things I wrote...

Is there an easy way to do this easy task?


Update: Partial solution

In bash, the solution is pretty simple, there is a history command, and there are ports of the idea:

IRB: Tweaking IRB

Cmd: Use PowerShell -> Get-History (or use cygwin)


Another Update: I found that doskey have a parameter history to do this:

cmd: Doskey /history >> history.cmd


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜