V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
tedzhou1221
V2EX  ›  Bash

刚想学 Shell,但 Demo 看不明白~

  •  
  •   tedzhou1221 · Jan 26, 2017 · 1972 views
    This topic created in 3380 days ago, the information mentioned may be changed or developed.
    #! /bin/sh
    
    a=1
    b=3
    
    if test $b=$a 
    then 
    	echo "you input 1"
    elif test $b=2  
    then
    	echo "you input 2"
    else
    	echo "you input $b"
    fi
    

    输出:

    you input 1


    为什么上面的输出结果是这样?

    不是应该输出 you input 3 吗?

    Ellison
        1
    Ellison  
       Jan 26, 2017
    =是判断字符串
    jookr
        2
    jookr  
       Jan 26, 2017 via iPhone
    if test $b=$a

    应该是

    if test $b==$a
    tedzhou1221
        3
    tedzhou1221  
    OP
       Jan 27, 2017
    @jookr Demo 上是=的,我试过==,结果也是一样~~
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3837 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 51ms · UTC 05:18 · PVG 13:18 · LAX 22:18 · JFK 01:18
    ♥ Do have faith in what you're doing.