This page is READ-ONLY. It is generated from the old site.
All timestamps are relative to 2013 (when this page is generated).
If you are looking for TeX support, please go to VietTUG.org

&& and ||

It is not simple
Added by ruby 8 months ago  »  Votes: 3/3

You may think these codes are the same

  1. Method A
1 [[ ! -f "/my/file" ]] || echo "File found" 
2 echo "Love will never lie" 
  1. Method B
1 [[   -f "/my/file" ]] && echo "File found" 
2 echo "Love will never lie" 

The purpose is to print out the string File found if the file /my/file does exist.

What is the difference? Try with set -e and you will see ;) If the file /my/file does not exist, you will never see the string Love will never lie in the method B. Why the difference? The first code will always return TRUE, the second one may return FALSE.

See also (blog) Bash: some useful "set".


Comments