大家来丢硬币阿!!
代码:
#!/bin/bashMAXTHROWS=$1 HEADS=0 TAILS=0throw=0
print_result(){echo the HEADS = $HEADSecho the TAILS = $TAILSecho }
update_count(){case $1 in0)let " HEADS += 1";;1)let " TAILS += 1" ;;esac}
echo
while [ "$throw" -lt "$MAXTHROWS" ]dolet "coin = $RANDOM % 2 "update_count $coinlet "throw += 1"done
print_result