Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Simple Question - && vs ;
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
red_over_blue
Guru
Guru


Joined: 16 Dec 2002
Posts: 310

PostPosted: Sat May 31, 2003 1:51 am    Post subject: Simple Question - && vs ; Reply with quote

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
View user's profile Send private message
duff
Guru
Guru


Joined: 19 Jun 2002
Posts: 466
Location: Clemson, SC

PostPosted: Sat May 31, 2003 2:10 am    Post subject: Reply with quote

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
View user's profile Send private message
duff
Guru
Guru


Joined: 19 Jun 2002
Posts: 466
Location: Clemson, SC

PostPosted: Sat May 31, 2003 2:46 am    Post subject: Reply with quote

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
View user's profile Send private message
red_over_blue
Guru
Guru


Joined: 16 Dec 2002
Posts: 310

PostPosted: Sat May 31, 2003 2:55 am    Post subject: Reply with quote

Thanks alot... I'll definitely use them differently now!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum