Email address obfuscation in effect -- please
click here to turn it off.
[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
> Ok.. I have a question about typing out commands in a shell:
>
> What is the difference between:
>
> make dep && make bzImage
>
> and
>
> make dep ; make bzImage
>
>
> Does the first one only run "make bzImage" if the "make dep" runs
> successfully? And the second one just run one command after another, not
> checking the return value from the one before it?
That is correct. What is going on behind the scenes is that:
x && y && z && ...
is a statement whose value will be true or false. The point is how it is
evaluated. In normal logic to evaluate the statement "a AND b AND c AND
.. " each term a, b, c, ... is checked for true or false and the the
answer returned. With the shell (and most programming languages - C, C++,
Java, perl, ...) this construct is evaluated "lazily" so that as soon as
one of the statements returns false (i.e. has a non-zero exit status) then
the shell knows that the whole statement will evaluate to false and it
stops right there. This is convenient if you only want one command
executed if the preceding command was successful.
The other form "x ; y ; ... " simply says "execute these commands in
order".
You can also use OR in the same way: "x || y" means run y only if x fails.
For example run this (not as root):
cat /var/spool/mail/root || echo "Doh"
Cheers, Rob
--
To manage your subscription, go to http://mlug.missouri.edu/members/edit.php
Archives are available at http://mlug.missouri.edu/list-archives/