Create Script from Bash History
The script program (bsdutils) will output the whole terminal output to a file. This can be helpful for logging and creating scripts out of history.
The approach here is to output the command history to a file and then manipulate the file a bit to get what we want.
history 3 > script.sh
This will output the last 3 commands to script.sh. Note that the actual history command will become the most recent event in history, and will be output in the file. This can be edited out manually or using this command: