| View previous topic :: View next topic |
| Author |
Message |
red_over_blue Guru


Joined: 16 Dec 2002 Posts: 310
|
Posted: Sat May 31, 2003 1:51 am Post subject: Simple Question - && vs ; |
|
|
I've got a simple question that probably has a simple answer. What is the difference between using && and ; to seperate commands in the CLI?
I tried searching google and these forums, but && and ; are hard to search for
Thanks. |
|
| Back to top |
|
 |
duff Guru


Joined: 19 Jun 2002 Posts: 466 Location: Clemson, SC
|
Posted: Sat May 31, 2003 2:10 am Post subject: |
|
|
| Code: | $ false; echo "hello"
hello
$ false && echo "hello"
|
";" will execute the next statement even if the first one fails. "&&" will only execute the next statement if the first one returns successfully. |
|
| Back to top |
|
 |
duff Guru


Joined: 19 Jun 2002 Posts: 466 Location: Clemson, SC
|
Posted: Sat May 31, 2003 2:46 am Post subject: |
|
|
There's another one also, "||" will execute the second statement, only if the first one fails:
| Code: | $ false || echo "hello"
hello
$ true || echo "hello"
|
|
|
| Back to top |
|
 |
red_over_blue Guru


Joined: 16 Dec 2002 Posts: 310
|
Posted: Sat May 31, 2003 2:55 am Post subject: |
|
|
| Thanks alot... I'll definitely use them differently now! |
|
| Back to top |
|
 |
|