You are not logged in.

#1 2004-08-03 16:07:50

yak8998
Member
Registered: 2004-03-01
Posts: 143

easy question reg: &&

Wow, I can't believe I didn't figure this out earlier (providing I actually did figure it out).

The '&&' will have the second command execute after the first completes, correct?

thx


"Ignorance is bliss, for stupid people."
"open-source is [...] programming Darwinism."
Vaughan-Nichols

Offline

#2 2004-08-03 16:23:19

dp
Member
From: Zürich, Switzerland
Registered: 2003-05-27
Posts: 3,363
Website

Re: easy question reg: &&

hey, i learned something! cool!!

i didnt know about && but i use ; for the thing oyu mentioned

[damir@Asteraceae /]$ echo 'what?'; sleep 2;echo 'this!'
what?
this!
[damir@Asteraceae /]$ echo 'what?' && sleep 2 && echo 'this!'
what?
this!
[damir@Asteraceae /]$ 

and it seems, that ; is the same as && indeed


The impossible missions are the only ones which succeed.

Offline

#3 2004-08-03 16:25:14

Xentac
Forum Fellow
From: Victoria, BC
Registered: 2003-01-17
Posts: 1,797
Website

Re: easy question reg: &&

&& will only run if the first command was completed successfully.  It harkens back to the lazy conditional evaluation of C.

In contrast || will only run if the first command fails, which is why the default PKGBUILD has a 'make || return 1' in it


I have discovered that all of mans unhappiness derives from only one source, not being able to sit quietly in a room
- Blaise Pascal

Offline

#4 2004-08-03 16:47:25

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: easy question reg: &&

and If you want a second command to run after the first command completes, regardless of its return status, you just separate them with a ;

For example:

pacman -Syuw; hang; halt

ensures than my dialup connection will hang up and shut down in the middle of the night after downloading (but not installing) all the packages that are out of date. It will also hang up as soon as pacman chokes and quits without completing the download, saving my dialup hours.

Dusty

Offline

#5 2004-08-03 16:47:54

dp
Member
From: Zürich, Switzerland
Registered: 2003-05-27
Posts: 3,363
Website

Re: easy question reg: &&

to use || (OR) in a script is logical, but && is the "AND", and (at least for me) does not make much sense using this way, so i never tried - funny - thanx for explaination


The impossible missions are the only ones which succeed.

Offline

Board footer

Powered by FluxBB