#!/bin/bash
cd ~
echo "give me the top price"
read int1
int2=$RANDOM
while [$int2 -ge $int1]
do
int2=$RANDOM
echo "guess!"
done
read int3
while [$int3 -ge $int2]
do
if [$int3 -gt $int2]
then
echo "smaller"
read int3
fi
if [$int3 -lt $int2]
then
echo "bigger"
read int3
fi
done
if [$int3 -eq $int2]
then
echo "you win!"
fi
要求进行猜数游戏,先由用户给上线,生成随机数,直到猜对为止。
报错是
~/test$ ./guessprice.sh
give me the top price
50
./guessprice.sh: line 6: [16638: command not found
./guessprice.sh: line 12: [: missing `]'
./guessprice.sh: line 25: [: missing `]'
格式不对吧, [ ] 离括号近的地方,加个空格试试。
-le ?
$RANDOM?