From owner-freebsd-chat@FreeBSD.ORG Tue Jul 28 13:52:55 2009 Return-Path: Delivered-To: freebsd-chat@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 35DD410656C0 for ; Tue, 28 Jul 2009 13:52:55 +0000 (UTC) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (lurza.secnetix.de [IPv6:2a01:170:102f::2]) by mx1.freebsd.org (Postfix) with ESMTP id 941168FC08 for ; Tue, 28 Jul 2009 13:52:54 +0000 (UTC) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (localhost [127.0.0.1]) by lurza.secnetix.de (8.14.3/8.14.3) with ESMTP id n6SDqYBZ017296; Tue, 28 Jul 2009 15:52:49 +0200 (CEST) (envelope-from oliver.fromme@secnetix.de) Received: (from olli@localhost) by lurza.secnetix.de (8.14.3/8.14.3/Submit) id n6SDqXur017295; Tue, 28 Jul 2009 15:52:33 +0200 (CEST) (envelope-from olli) Date: Tue, 28 Jul 2009 15:52:33 +0200 (CEST) Message-Id: <200907281352.n6SDqXur017295@lurza.secnetix.de> From: Oliver Fromme To: freebsd-chat@FreeBSD.ORG, emailrob@emailrob.com In-Reply-To: <4A6E3B17.7030609@emailrob.com> X-Newsgroups: list.freebsd-chat User-Agent: tin/1.8.3-20070201 ("Scotasay") (UNIX) (FreeBSD/6.4-PRERELEASE-20080904 (i386)) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.1.2 (lurza.secnetix.de [127.0.0.1]); Tue, 28 Jul 2009 15:52:49 +0200 (CEST) Cc: Subject: Re: [ fbsd_chat ] sh(1) docs [ was: Bourne shell short-circuit operators improperly documented ] X-BeenThere: freebsd-chat@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: freebsd-chat@FreeBSD.ORG, emailrob@emailrob.com List-Id: Non technical items related to the community List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Jul 2009 13:52:55 -0000 spellberg_robert wrote: > my killer_app, -- a priori --, depends upon > the use of a good general_purpose macro_processor [b]. > i thought that i had found one in m4(1), Personally I think m4 is weird and error-prone. Another possibility is to use cpp (the C preprocessor). It's not perfect either, but maybe it's more suitable for your purpose. > therefore, i re_evaluated the use of sh(1). > it will do almost everything that i want, excluding, specifically, > a] sub_stringing by character_count [c]; You can define a shell function that uses dd(1): $ substr() { echo "$1" | dd bs=1 skip=$2 count=$3 2>/dev/null; } $ foo=`substr "FreeBSD" 4 3` $ echo $foo BSD $ It's not terribly efficient, because dd(1) is an external binary that has to be exec*()ed by the shell. So it might be slow if you use the substr function often. It is possible to write this function using shell-builtin commands only (no exec*() necessary), but it requires a loop. Whether this is faster or slower I can't tell, it probably depends on the circumstances. Shell loops that use only builtin features are usually fast enough for normal script, unless you try to abuse sh(1) and use it like a programming language. In that case you're advised to use something better suited for the purpose, like Python (my personal favourite), Ruby, Perl or similar. > b] arithmetic on integers, of width 37_bits or so [ let's say, 40 ]; This has been improved. Recent versions of FreeBSD 7 and 8 use 64 bit arithmetic, like most other shells. > c] more_than_minimal string conditionals > [ "test" is, understandably, file_oriented ]. There is also expr(1) and other tools. Apart from that, you should be able to implement what you need with shell functions. Is there anything in particular that you are looking for? > i do not expect a man_page to be a tutorial, Right. Man pages are reference documentation. They're not typically used for tutorials, recipes or "how-to". There are quite many books on the topic of bourne shell. (I mean real books, i.e. paper ware. There might be online books, too, but I'm not aware of a good one right now that I could recommend.) > man_pages need to be, at least, "substantially_complete". I agree that the sh(1) manual page should be complete, and I think it is indeed complete. Do you think some piece of reference information is missing? > second, i can understand the "tour" being out_of_date somewhat, > perhaps, even by a few years, > but, --twenty-- years ? Probably it is kept only for historical purposes. The developers working on the sh(1) source certainly don't need that "tour" file. > i could be wrong, but, > i suspect that sh(1) doesn't change much from year to year. Well, it depends on what you call "doesn't change much". >From time to time it grows a new feature (like the 64bit arithmetics last year) or a new builtin. Sometimes a builtin is even removed, like the printf command which used to be builtin, but was removed in favour of the external command. And sometimes bugs are fixed, of course. Best regards Oliver -- Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M. Handelsregister: Registergericht Muenchen, HRA 74606, Geschäftsfuehrung: secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün- chen, HRB 125758, Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart FreeBSD-Dienstleistungen, -Produkte und mehr: http://www.secnetix.de/bsd "Unix gives you just enough rope to hang yourself -- and then a couple of more feet, just to be sure." -- Eric Allman