#!/bin/bash ring_bell() { freq=$1; tick=$2 # 通过频率freq算周期circ circ=$(echo "scale=3; 60/$freq" | bc) for ((i=0; i<tick; ++i)); do echo -en '\a' # 响铃 sleep $circ # 延时一个周期 done } usage() { echo 'Usage: ring <freq> <ticks>' } ########################################## if [ $# -lt 2 ]; then usage exit fi ring_bell $1 $2