Whenever I am writing a script in perl or bash, I always wish that there
was some way to have all the commands logged or output to screen. I know
there is “set -x” option to have debugging enabled, but sometimes that
seems to be too much information and I dont really need all that. So, here
is something I found recently for bash to log all the executed commands.
trap "echo $BASH_COMMAND" DEBUG
This will echo/print all the commands on the stdout.
For me, I mostly forget to add “sudo” to the command until the time I am actually supposed to run it. Also sometimes, on some systems, bash completion does not work as expected with “sudo”. With these in mind, I wanted something such that when I have completed the command, I could insert sudo in the begining of the command without much ado. So, finally this is what I came up with in my “~/.inputrc” file. Note: If you don’t have this file, then simply create this file.