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 delete history and register every command runned from that moment and echo it in a file. This is what i make but dont 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