$ cat cheapwatch
#!/bin/sh
# Not quite your Rolex
while true ; do
clear
printf "[%s] Output of %s:\n" "$(date)" "$*"
# "$@" <- we don't want to do it this way, just this:
${SHELL-/bin/sh} -c "$*"
sleep 1 # genuine Quartz movement
done
$ ./cheapwatch ls --color # no problem
#!/bin/sh
trap "tput cnorm" EXIT # unhide the cursor when the script exits or is interrupted
# simple interval parameter parsing, can be improved
INTERVAL=2s
case $1 in
-n|--interval)
INTERVAL="$2"
shift; shift
;;
esac
clear # clear the terminal
tput civis # invisible cursor, prevents cursor flicker
while true; do
tput cup 0 0 # move cursor to topleft, without clearing the previous output
sh -c "$*" # pass all arguments to sh, like the original watch
tput ed # clear all to the end of window, if the new output is shorter
sleep "$INTERVAL"
done