Bash break while loop by user input
问题 I got me a little stopwatch which I put into bashrc with the following code: stopwatch() { date1=`date +%s` echo $1 while true; do echo -ne "$(date -u --date @$((`date +%s` - $date1)) +%H:%M:%S)\r" done } The ouput would look like this while the time would just count up in the second line: ~$ stopwatch test test 00:00:04 Now if I want to end the stopwatch I press Ctrl+C which gives me this: ~$ stopwatch test test ^C:00:03 I'd like to end the loop while containing its ouput using e.g. my enter