Timeline for How exactly does `if $cmd ; then $cmd ; fi` differ from `$cmd && $cmd`?
Current License: CC BY-SA 3.0
9 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jun 2, 2014 at 0:21 | vote | accept | mikeserv | ||
| Jun 2, 2014 at 0:31 | |||||
| Jun 2, 2014 at 0:09 | comment | added | Hauke Laging | @mikeserv Whatever. As I recently learnt the hard way you can change the accepted answer later. That's probably easier as you are notified about new answers but AFAIR not reminded of accepting one. I would be a bit surprised to see other answers here anyway... | |
| Jun 2, 2014 at 0:03 | vote | accept | mikeserv | ||
| Jun 2, 2014 at 0:06 | |||||
| Jun 1, 2014 at 23:56 | comment | added | Hauke Laging | @mikeserv I have added the explanation from my question comment to the answer. | |
| Jun 1, 2014 at 23:55 | history | edited | Hauke Laging | CC BY-SA 3.0 | added 459 characters in body |
| Jun 1, 2014 at 23:38 | comment | added | mikeserv | Agreed that the evaluation is equivalent, but the parsing is not, which is what I think I got wrong. Honestly, as I said before, I so seldom use if...fi that I didn't really know, and I thank you for teaching me, but the question is how do they differ? because someone said I was wrong when I said they were equivalent for basically the exact same reasons. So, I guess what I'm asking you to do is to specifically address the question if you would. | |
| Jun 1, 2014 at 23:32 | comment | added | Hauke Laging | @mikeserv I guess it's an exact elif. &&/|| is always if [ $? -eq 0 ] / if [ $? -ne 0 ] but that doesn't mean that the whole construct is not equivalent to if elif else fi | |
| Jun 1, 2014 at 23:12 | comment | added | mikeserv | Thanks, Hauke. The elif isn't exactly elif, though, right? It's if...fi ; if [ $? = 0 ] .... Same goes for else... approximation as well, I guess, which is why I deleted my comment before - not only is there no elif there's not even any else..., really, only if.../if !..., I guess. It was your own comments that led me to understand that a little better, I think. So I upvoted your answer, but if you could talk about that angle a little I'd accept it. Unless I'm wrong again... Oh, and just echo true - echo always returns 0. | |
| Jun 1, 2014 at 22:57 | history | answered | Hauke Laging | CC BY-SA 3.0 |