Enabling History in Shell Scripts

If you've ever found yourself trying to log the commands ran by your bash scripts (and cursed your failures to quote and escape them properly), then try using bash's built in history functionality instead. Below is in example of how to turn it on within a script.

#!/bin/bash
 
HISTFILE="$0.log"
set -o history
history -c
 
echo 'Those who cannot remember the past are condemned to write their own logging functions.'
 
history -w
blog/enabling_history_in_shell_scripts.txt · Last modified: 2009/10/22 15:28 by brian
Recent changes · Show pagesource · Login