From owner-freebsd-newbies Mon Jun 22 17:08:20 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id RAA28832 for freebsd-newbies-outgoing; Mon, 22 Jun 1998 17:08:20 -0700 (PDT) (envelope-from owner-freebsd-newbies@FreeBSD.ORG) Received: from pau-amma.whistle.com (s205m64.whistle.com [207.76.205.64]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id RAA28738 for ; Mon, 22 Jun 1998 17:07:55 -0700 (PDT) (envelope-from dhw@whistle.com) Received: (from dhw@localhost) by pau-amma.whistle.com (8.8.7/8.8.7) id RAA00408; Mon, 22 Jun 1998 17:06:53 -0700 (PDT) (envelope-from dhw) Date: Mon, 22 Jun 1998 17:06:53 -0700 (PDT) From: David Wolfskill Message-Id: <199806230006.RAA00408@pau-amma.whistle.com> To: fewtch@serv.net, jlemon@americantv.com Subject: Re: Latest discoveries... Cc: freebsd-newbies@FreeBSD.ORG Sender: owner-freebsd-newbies@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >Date: Mon, 22 Jun 1998 09:48:03 -0700 >From: Tim Gerchmez >> alias dofloppy 'fdformat fd0; disklabel -w fd0 fd1440; mount /dev/rfd0 >/mnt' >>Although I don't really recommend that; if one of the commands >>errors, the next is executed anyway, which is probably not what >>you want. >It wouldn't be a problem, just hit Ctrl-C to abort. In order to provide an alternative for folks whose circumstances are such that ^C isn't a reasonable course, I'll point out that ';' isn't the only command separator available. In particular, if the command is such that it generates a zero "return code" if and only if(*) it completes "successfully" -- that is, with no errors detected -- it may be useful to use either "&&" or "||" as a command separator. "&&" would be used for a situation where the command to the (immediate) right of the separator should be executed after the left-hand command has terminated with a zero return code. If the left-hand command terminates with a non-zero return code, the right-hand command will not be executed. An example of this usage would be for rebuilding the kernel, where I might type: config PAU-AMMA && cd ../../compile/PAU-AMMA && \ make depend && make && make install && reboot (except that I inserted the "\" and newline to make the result easier to read.) In this case, if an error is detected at any point in the process, progress stops, and I get to review things. I learned this trick from reviewing Geoff Collyer & Henry Spencer's shell scripts that they (mostly Geoff, as I recall) wrote for C News, around 1988 or so. Similarly, "||" would be used if the right-hand command is to be executed after the left-hand one has terminated with a non-zero return code -- like "foo || echo 'Oops -- something failed'". FAIR WARNING: Not all commands are well-behaved with respect to terminating with return codes that are useful for this type of thing. It is usual for different commands to be implemented by different (sets of) people for different reasons with different goals. If you are in doubt, test first... and check the documentation, as well, so that even if it happens to work once, it won't be because of dumb luck. Be careful of using "undocumented programming interfaces". If the actual behavior deviates from the documented behavior, become familiar with the command "send-pr" -- and *use* it (once you're sure you've encountered a real discrepancy between documented vs. actual behavior). * "if and only if" is used in the above in the sense in which it tends to be used in mathematics -- if either condition obtains, the other may logically be inferred; either follows from the other. david -- David Wolfskill UNIX System Administrator dhw@whistle.com voice: (650) 577-7158 pager: (650) 371-4621 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-newbies" in the body of the message