Buzz Image   SUBMIT

Interested in buying this domain?
I have a python application I use for taking notes in markdown. It automates several tasks for me and one of those tasks is parsing my command history and logging certain commands to a markdown file.

Parsing out the command and even the timestamp of each command (if your bashrc is setup correctly) in the Bash_History file is easy. However, what if one of these commands was typed wrong or perhaps I forgot a parameter or flag which caused the command to fail. There isn't any bash/zsh environment variable I can set to add this bit of information to the bash_history file like you would for including the timestamp.

How can I effectively and most easily solve this problem?

To be extra clear. Say I have a bash_history file with the following commands. How can I distinguish between failed/succeeded commands?

---Bash_History File---


ls -la




For simplicity, lets say I want to parse this file and log all these commands that succeeded but ignore the commands that failed which are <lsla> and <cdd>. Obviously <lsla> is wrong as it's missing the space and '-' character. The <cdd> is wrong cause (for sake of argument) lets say I fat fingered this command. That leaves two commands that succeeded. For a Bash_History file of 5,000 commands this becomes more complicated as each command could have several ways it could look (such as different params and options). So a lookup "dictionary" type of method wouldn't work here.

Therefore, how can I easily determine which commands succeeded and which failed?

What method would best work across both bash/zsh?

Are there environment variables I have to set? For example, to see the timestamp of each command I set the following variable in my bashrc


Do I need to write my own bash_history program for this? Would like to avoid that.