我可以在脚本中自动使用我在 shell 上编写的内容(bash、cmd、irb 等)吗?
总体思路非常简单,我想为某个任务制作一个脚本,我在 shell(任何 shell)中执行它,然后我想复制我使用过的命令。
如果我复制窗口中的所有内容,那么我就有很多内容需要删除和更正。 (并且不容易从 shell 复制)
简历:我想获取我写的所有内容...
有没有一种简单的方法来完成这项简单的任务?
更新:部分解决方案
在bash中,解决方案非常简单,有一个history命令,并且有这个想法的端口:
IRB:调整 IRB
Cmd :使用 PowerShell -> Get-History(或使用 cygwin)
另一个更新: 我发现 doskey 有一个参数历史来执行此操作:
cmd:Doskey /history>>历史记录.cmd
The general idea is pretty simple, I want to make a script for a certain task, I do it in the shell (any shell), and 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,您可以使用:
这会将您的命令历史记录保存到 filename.sh 中。您可能需要对其进行编辑,以仅保留命令序列末尾的行。
注意:这是一个 bash 命令,不适用于所有 shell。
Yes, you can use:
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 会让你进入一个新的 shell 并保存
所有输入和输出都保存到名为 typescript 的文件中。当你们完成互动后,
退出外壳。然后,文件 typescript 就可以进行 grep 分析了。例如,您可能
grep 查找提示并将输出保存到文件中。如果您像我一样是一个笨手笨脚的打字员,那么您可能需要做一些清理工作来删除退格键。曾经有一个程序可以做到这一点,但我现在似乎找不到它。这是我在
'net: http://www.cat.pdx.edu/tutors/files /fixts.cpp
如果您想跟踪整个交互式会话并将其发布到网络上,此方法特别有用。
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.