[Techtalk] the finer points of kernel customization
Travis Casey
efindel at earthlink.net
Tue Mar 23 08:59:17 EST 2004
On Tuesday 23 March 2004 00:40, John Clarke wrote:
> I usually build and install with:
>
> make oldconfig && make dep && make bzImage modules install
> modules_install
> For those not familiar with "make", you can give it multiple targets
> (arguments) and it will build them all in turn, stopping at the first
> failure (unless you add "-k"). The "&&" between each command ensures
> that each is run only if the previous ones ran successfully.
Just to clarify for folks -- the "&&" part isn't anything to do with make,
it's a shell thing... and thus can be used in scripts.
Using "&&" for this is a trick. "&&" actually does the logical "and"
function -- namely
command 1 && command 2
returns 0 (which is "true" in shell-ese) if both command 1 and command 2
ran and didn't return any error codes.
So why can you use it for the above and not have anything else run if, say,
"make oldconfig" fails?
Well, like many other programming languages, shells make optimizations. For
an "&&", if the first command returns an error, then we know that the "&&"
as a whole is now "false" -- you only get "true" if *both* commands run
without errors. So, the shell doesn't even bother running the second
command -- it has enough information to return the value of the "&&". That
allows it to be used as a substitute for "if" -- doing things out with if,
though, would make the command much more unwieldy, especially for typing at
a command line:
if make oldconfig ; then if make dep ; then make bzImage modules install
modules_install ; fi fi
... is a lot more typing and chances to mess up.
There's a corresponding trick with ||, the shell "or". If the first command
in an "or" returns true (i.e., exits normally), then there's no need to run
the rest of the "or" -- we know the whole "or" is true. And shell again
"shortcuts" by not running the rest. Thus, || can be used as a substitute
for "if not X" just as and can be used as a substitute for "if X":
tar xf transfer_file || echo "could not untar transfer_file"
for example.
It should be noted that this isn't shell-specific. The same "idioms" show
up in Perl, C, and other languages where these evaluation shortcuts are
used. Not all computer languages shortcut evaluation this way, though, so
it's wise to check a language's specification before using these tricks.
--
|\ _,,,---,,_ Travis S. Casey <efindel at earthlink.net>
ZZzz /,`.-'`' -. ;-;;,_ No one agrees with me. Not even me.
|,4- ) )-,_..;\ ( `'-'
'---''(_/--' `-'\_)
More information about the Techtalk
mailing list