Chinaunix

标题: 如何测试一个变量的值? [打印本页]

作者: yyf_007    时间: 2004-02-26 16:24
标题: 如何测试一个变量的值?
我做了一个选单,想根据选择做相应的事情,变量的值来是正确的,但是我的if语句没有作用。
原代码如下,哪位大哥帮我看看?

#!/bin/sh
DIALOG=${DIALOG=/usr/bin/dialog}
$DIALOG --clear --title "Welcome to Ada game Console" \
        --hline "ress 1-4, first letter or Enter" \
        --menu "Wellcoem user Ada GameMaster Software.  You Will be easyer\n\
                  Choose the OS you like:" -1 -1 4 \
        "1 "        "Set ip addres " \
        "2"          "Halt and Restart" \
        "3"         "Halt and Power  off" \
        "4"         "Exit "  2> /tmp/menu.tmp.$$

retval=$?
choice=`cat /tmp/menu.tmp.$$`
rm -f /tmp/menu.tmp.$$
case $retval in
  0)
        echo $choice
        sleep 20
        if $choice==1
        then
                dialog --input "Input IP Addres(Ex.x.x.x)" -1 -1 "192.168.0.123" >/tmp/a
                ip =`cat /tmp/a`
                rm /tmp/a
                echo $ip               
                sleep 20
        fi
       
        echo "'$choice' chosen.";;
  1)
    echo "Exit Menu.";;
  255)
    [ -z "$choice" ] || echo $choice ;
        exit -1
       
esac
clear
作者: 網中人    时间: 2004-02-26 18:05
标题: 如何测试一个变量的值?
if $choice==1
改為:
if [ "$choice" = 1 ]




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2