I have to make a script that print all commands used by user. So I try to make a script that will run in background and which deletes history and registers every command runned from that moment and echo it in a file. This is what I did but it doesn't work.
function add_new_command() {
nr=$(history | wc -l)
if [ $nr -eq 1 ]; then
comanda=$(history | head -n 1)
echo $comanda > mycommands
history -c
fi
}
history -c
while true
do
add_new_command
done
A much better approach is to use the built-in variables for controlling history.