if statement - What is the correct way to use the bash if else && || shortcut? -


I have come across some weird behavior (is not mutually weird, but I do not understand it). >

I have to write something if / to the statements, using the statement of the shorthand syntax:

  [[1-1 points]] & amp; Amp; Echo "true" || Returns the output of the code given above:  
  true   

Now the above code works really well. But it does not make the next code:

  [[1-IQ1]] & amp; Amp; InfMsg "True" || InfMsg "false"   

infMsg is just a function giving output given by the above code:

  true false   

I just want to say it 'true'.

What is the way I & amp; Amp; Amp; || Does the syntax handle the exit code for tasks?

I doubt that your exit code for 'infMsg' is 0 (success). If we break the first piece of code:

  [[1-IQ1]] & amp; Amp; Echo "true" || What's happening:  
  • [[1-EMBA 1]] & amp; There is a higher priority than and to = (more info [here] The first part of the code is "true"
  • the first half truth of that return Then, the first half is true , the second half is the "true" echo (& Amp; - & gt; if the part is true, the second part )
  • Now we have || "wrong" echo This part really returns the first half ( resonant "true" ) Have done so because successfully print echo

    Now if we break the second piece of code:

     < Code> [[1-1 points]] & amp; amp.com; InfMsg "true" ||  
    • [[Anyone can be ] & amp; amp; InfMsg "true" has been evaluated The first side is true, after that, the first half was true , Executes the second half infMsg "true" statement (& amp;; - & gt; if part is true, run second part).
    • We now have || If the status code interpreted as the success status (0) is not returned, then the first half is called False, if InfMsg is "incorrect" if the previous command from INMsg "true" ( (- -> If the part is a liar, then run the other part).

      Important information to go away here:

      • || The second half runs only if the first half is wrong.
      • & amp; Amp; If the first half is TRUE, then only run the second half.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -