抓阄脚本

回复 收藏
dushu(){
read -p "please input your name:" n
score=$[RANDOM%100]
echo "your score is $score"
echo $n $score >> 1.txt
x2=`sed -n '2'p 1.txt`
}
shouci(){
read -p "please input your name:" n
score=$[RANDOM%100]
echo "your score is $score"
echo $n $score >> 1.txt
}
panduan(){
if [ $x1 -ge $x2 ];then
x3=$x1
echo 你输了
elif [ $x1 -eq $x2 ];then
x3=$x1
echo 平局
else
x3=$x2
echo 你输了
fi
x1=$x3
echo $x1 > 1.txt
}
jixu(){
read -p "Do you want to continue?[y/n]" t
if [ $t = y ];then
dushu
else
break
fi

}
shouci
shouci
x1=`cut -d '' -f1 1.txt|sed -n '1'p`
x2=`cut -d '' -f1 1.txt|sed -n '2'p`
panduan
while :;do
jixu
panduan
done
花了几个小时,脚本有些小问题,会有错误提示:
1.sh: line 15: [: too many arguments
1.sh: line 18: [: too many arguments
望指正。。
2016-05-28 11:01 举报
已邀请:
0

duyanbin

赞同来自:

没太看明白脚本的意思,但
x1=`cut -d '' -f1 1.txt|sed -n '1'p`
x2=`cut -d '' -f1 1.txt|sed -n '2'p`
这两行 cut -d 后面的分割符貌似应该是 ' ' ,也就是得空一个格  , 然后估计你想得到数字,所以 应该是 -f2
也就是改成 x1=`cut -d ' ' -f2 1.txt|sed -n '1'p`

照这个逻辑,dushu()函数中的
x2=`sed -n '2'p 1.txt` 也得改一改 ,这个获取到的值不是数字
0

等风来

赞同来自:

duyanbin 发表于 2016-5-28 19:31
没太看明白脚本的意思,但
x1=`cut -d '' -f1 1.txt|sed -n '1'p`
x2=`cut -d '' -f1 1.txt|sed -n '2'p` ...

恩恩,谢了,貌似是这样
0

等风来

赞同来自:

duyanbin 发表于 2016-5-28 19:31
没太看明白脚本的意思,但
x1=`cut -d '' -f1 1.txt|sed -n '1'p`
x2=`cut -d '' -f1 1.txt|sed -n '2'p` ...

恩恩,谢了,貌似是这样
0

等风来

赞同来自:

dushu(){
read -p "please input your name:" n
score=$[RANDOM%100]
echo "your score is $score"
echo $n $score >> 1.txt
x2=`cut -d ' ' -f 2 1.txt|sed -n '2'p`
}
shouci(){
read -p "please input your name:" n
score=$[RANDOM%100]
echo "your score is $score"
echo $n $score >> 1.txt
}
panduan(){
if [ $x1 -ge $x2 ];then
x3=$x1
echo 你输了
elif [ $x1 -eq $x2 ];then
x3=$x1
echo 平局
else
x3=$x2
echo 你输了
fi
x1=$x3
echo $x1 > 1.txt
}
jixu(){
read -p "Do you want to continue?[y/n]" t
if [ $t = y ];then
dushu
else
break
fi

}
shouci
shouci
x1=`cut -d ' ' -f2 1.txt|sed -n '1'p`
x2=`cut -d ' ' -f2 1.txt|sed -n '2'p`
panduan
while :;do
jixu
panduan
done
脚本已经改正了,运行没问题,就是楼上说的问题

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: