Skip to main content
edited title
Link
tshepang
  • 67.7k
  • 94
  • 226
  • 297

Bash: Keep only successful commands in BASH history

Tweeted twitter.com/#!/StackUnix/status/217974260591894529
Source Link
Adam Matan
  • 2.7k
  • 6
  • 31
  • 32

Bash: Keep only successful commands in history

Sometimes I misunderstand the syntax of a command:

# mysql -d test
mysql: unknown option '-d'
# echo $?
2

I try again and get it right:

# mysql --database test
Welcome to the MySQL monitor.
mysql >
...

How do I prevent the first command, with error code different than 0, to enter the history?