Date: Mon, 22 Jun 1998 17:06:53 -0700 (PDT) From: David Wolfskill <dhw@whistle.com> To: fewtch@serv.net, jlemon@americantv.com Cc: freebsd-newbies@FreeBSD.ORG Subject: Re: Latest discoveries... Message-ID: <199806230006.RAA00408@pau-amma.whistle.com>
next in thread | raw e-mail | index | archive | help
>Date: Mon, 22 Jun 1998 09:48:03 -0700 >From: Tim Gerchmez <fewtch@serv.net> >> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199806230006.RAA00408>