+ -
当前位置:首页 → 问答吧 → 帮看看问题出在哪。谢谢

帮看看问题出在哪。谢谢

时间:2011-05-01

来源:互联网

本帖最后由 ubuntu_mark 于 2011-05-01 11:34 编辑

描述:                             
                                 A
                                  ----------------------
                                   |          |            |
                                  File    run.sh   Game
                                   |                        |
                                   |                        |
                           gamelist.txt              a.sh  b.sh



run.sh
#!/bin/bash
ls Game > File/gamelist.txt
echo "Game list:"
cat  File/gamelist.txt
echo please input the Game_name:
read Game_name
name=`grep $Game_name File/gamelist.txt`
echo $name
while [[ `echo $name` = '' ]]
do
  echo 'wrong name!'
  read Game_name
done
echo "-----run the $Game_name-----"
source Game/$Game_name

运行结果------------------
Game list:
a.sh
b.sh
please input the Game_name:
a.sh
a.sh
-----run the a.sh-----
Game list:
a.sh
b.sh
please input the Game_name:
wrong name!
wrong name!
wrong name!
wrong name!
wrong name!


问题是,我输入其中的游戏b.sh,游戏可以正常运行
        输入a.sh,就进入while循环了,不知道为什么循环2遍,一直打印‘wrong name’
        请问问题出在哪?是run.sh问题,还是a.sh可能引起的

作者: ubuntu_mark   发布时间: 2011-05-01

echo please input the Game_name: 虽然没什么问题,但是建议最好加引号

while [[ `echo $name` = '' ]]        // 你这个是要赋值还是条件?
do
  echo 'wrong name!'
  read Game_name                       //这个是在干吗?
done

echo "-----run the $Game_name-----"
source Game/$Game_name       //还有这个? 有必要吗?

作者: 南极雨   发布时间: 2011-05-01

我试了下,没问题啊!

作者: heylsitan12   发布时间: 2011-05-01

回复 南极雨


while [[ `echo $name` = '' ]]        // 想是条件
do
  echo 'wrong name!'
  read Game_name                       //如果输入错了,就再赋值
done

echo "-----run the $Game_name-----"
source Game/$Game_name       //想运行相应的游戏


大哥您就说该怎么修改,或者错在哪吧,谢谢

作者: ubuntu_mark   发布时间: 2011-05-01

回复 heylsitan12


    也不是特定的a,b,代称
   我也觉得没问题
   但是输入其中的一个名字可以,输入另一个就进循环了,不知道为什么

作者: ubuntu_mark   发布时间: 2011-05-01

本帖最后由 南极雨 于 2011-05-01 21:54 编辑

回复 ubuntu_mark


一共两行,read 逐行读取.第一行是a.sh 读取第二行的时候,name='',进入循环

我也有个问题要请教呢,呵呵你的while循环中有个read Game_name ,你是怎么跳出来循环的阿?

作者: 南极雨   发布时间: 2011-05-01

回复 ubuntu_mark


    路过,没有看明白是啥问题!

作者: yuloveban   发布时间: 2011-05-01