#!/bin/bash LOGFILE=log.txt function logcmd() { echo "$ $@" >> $LOGFILE $("$@") >> $LOGFILE } logcmd touch "foo file"