tedzhou1221
V2EX  ›  Bash

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

  •  
  •   tedzhou1221 · Jan 26, 2017 · 2389 views
    This topic created in 3598 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   ·   4669 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 01:39 · PVG 09:39 · LAX 17:39 · JFK 20:39
    ♥ Do have faith in what you're doing.