User Tools

Site Tools


bash

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
bash [2012/11/28 19:56]
k2patel [If File Comparision]
bash [2017/07/02 02:13]
k2patel old revision restored (2013/05/08 17:56)
Line 364: Line 364:
 HISTTIMEFORMAT="​[%Y-%m-%d - %H:%M:%S] - " HISTTIMEFORMAT="​[%Y-%m-%d - %H:%M:%S] - "
 </​code>​ </​code>​
 +
 +=== Truth Table ===
 +<code bash>
 +These two commands not the same:
 +
 +command1 && command2 || command3
 +
 +if command1
 +then
 +command2
 +else
 +command3
 +fi
 +</​code>​
 +
 +In the if-then-else,​ exactly one of command2 or command3 will be executed. But in the && || version, command3 runs if either command1 or command2 returns false.
 +
 +<code bash>
 +for c1 in true false; do for c2 in true false; do echo "$c1 && $c2 || c3"; (echo c1; $c1) && (echo c2; $c2) || echo c3; done; done
 +</​code>​
 +
 +And the output:
 +
 +<code bash>
 +true && true || c3
 +c1
 +c2
 +true && false || c3
 +c1
 +c2
 +c3
 +false && true || c3
 +c1
 +c3
 +false && false || c3
 +c1
 +c3
 +</​code>​
 +[[ http://​www.linkedin.com/​groups/​Tuesdays-tip-difference-between-if-3716796.S.236851680?​view=&​srchtype=discussedNews&​gid=3716796&​item=236851680&​type=member&​trk=eml-anet_dig-b_pd-ttl-cn&​ut=0FCRGmx_LdW5I1 | Link to Article ]]
 ==== Networked Info ==== ==== Networked Info ====
  
bash.txt ยท Last modified: 2020/08/10 02:35 (external edit)