ความแตกต่างระหว่าง && และ ; ใน shell script-different-symbol-in-shell-script

In the shell, && and ; are similar in that they both can be used to terminate commands.
The difference is && is also a conditional operator. With ; the following command is always executed, but with && the later command is only executed if the first succeeds.

false; echo “yes” # prints “yes”
true; echo “yes” # prints “yes”
false && echo “yes” # does not echo
true && echo “yes” # prints “yes”
Newlines are interchangeable with ; when terminating commands.

สรุปคือ ถ้าใช้ && ขั้น คือต้องรัน command แรกเสร็จแล้วค่อยรันอีก command ต่อ เช่น
true && echo “yes” # prints “yes”

แต่ถ้า ; ก็คือไม่สนใจว่า ประโยคข้างหน้าจะจริงหรือเปล่าให้ รัน command ที่สองเลย

Add A Comment

Your email address will not be published. Required fields are marked *