NBash
23 строки · 788.0 Байт
1#!/bin/bash
2
3# hilow -- Простая игра "угадай число"
4biggest=100 # Максимальное возможное число
5guess=0 # Число, предложенное игроком
6guesses=0 # Количество попыток
7
8number=$(( $$ % $biggest )) # Случайное число от 1 до $biggest
9
10echo "Guess a number between 1 and $biggest"
11while [ "$guess" -ne $number ] ; do
12/bin/echo -n "Guess? " ; read guess
13echo "guess=$guess"
14if [ "$guess" -lt $number ] ; then
15echo "... bigger!"
16elif [ "$guess" -gt $number ] ; then
17echo "... smaller!"
18fi
19guesses=$(( $guesses + 1 ))
20echo "guesses=$guesses"
21done
22echo "Right!! Guessed $number in $guesses guesses."
23exit 0