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---
lsla
ls -la
cdd
cd
---END OF FILE---
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 and . Obviously is wrong as it's missing the space and '-' character. The 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
HISTTIMEFORMAT="%d/%m/%y %T "
Do I need to write my own bash_history program for this? Would like to avoid that.