In ~/.bash_aliases I want to create an alias for repeat word that will repeat given command n times.
repeat() {
n=$1
shift
while [ $(( n -= 1 )) -ge 0 ]
do
"$@"
done
}
I want to use repeat to list updated files in a directory so I made following function (WAIT,CLEAR,LIST):
wcls() {
m=$1
shift
clear
date
ls -l "$@"
sleep $m
}
I have a folder where are my_file1 and my_file2. If I run the script :
repeat 500 wcls 2 my_file*
i get
my_file1 ...
my_file2 ...
and in the mean time I change my_file2 to my_file3 the script wont update the contents showing
my_file1 ...
my_file2 no such file or directory
what should I do for my functions to correctly handle asterisks?