Menu

Assist req'd with Mingw script.

David Wall
2021-09-02
2021-09-02
  • David Wall

    David Wall - 2021-09-02

    This is 'kinda' confusing me - I'm trying to run one of two options depending on the content of a variable previously set up via export.
    I'll display the script and then display the result - which is confusing me since it 'appears' the variable is passing the two different if tests - despite it only being valid for one of them.

    The script: called Mk

    export BV="V"
    echo $BV
    if [ "$BV"="B" ]
    then
    echo Found BDB
    fi
    if [ "$BV"="V" ]
    then 
    echo Found VBI
    fi
    

    The results:

    $ mk
    V
    Found BDB
    Found VBI
    

    What am I doing wrong ??.

    TIA - Thanks in anticipation.

     

    Last edit: Simon Sobisch 2021-09-02
  • Mickey White

    Mickey White - 2021-09-02

    Not sure, but I suppose since there is no spaces between the equals signs in the if statement, then it perceives it as a true type of Boolean?
    Try it with spaces on before and after the = sign in the if statement.

     
    👍
    1
    • David Wall

      David Wall - 2021-09-02

      Thank you Mickey - got it in 1 - much appreciated.
      I'd already switched the test to a case statement but the if looks better I think.

      Have a beer on me.

       

Anonymous
Anonymous

Add attachments
Cancel