tedzhou1221
V2EX  ›  Bash

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

  •  
  •   tedzhou1221 · Jan 26, 2017 · 2339 views
    This topic created in 3571 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
    Ellison
    Jan 26, 2017
    1
    =是判断字符串
    jookr
    jookr
    Jan 26, 2017 via iPhone
    2
    if test $b=$a

    应该是

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