Reputation: 103
I have written the following simple code in bash to automate the Fortune program in Ubuntu. $1 takes the file name and another command line input takes the number of fortune to show consecutively with 10 sec sleep in between. I would like you to help me in modifying the code so that if i press ENTER key, the sleep time of 10 secs will reduce to zero that means it will show the next 'fortune'. Thanks
#function myfortunelearn
myfortunelearn(){
cd $HOME/folder1/folder2
numberofitems=$1
shift
echo -e "\n"
for i in `seq $numberofitems`; do
fortune $@
sleep 10
echo -e "\n"
done
}
Upvotes: 0
Views: 60
Reputation: 120644
The easiest way to accomplish this would be to change:
sleep 10
To:
read -t 10
This will wait for input from the keyboard for 10 seconds, and return if it the timeout is exceeded without reading any input.
Upvotes: 3