Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 28 Jul 2009 15:52:33 +0200 (CEST)
From:      Oliver Fromme <olli@lurza.secnetix.de>
To:        freebsd-chat@FreeBSD.ORG, emailrob@emailrob.com
Subject:   Re: [ fbsd_chat ] sh(1) docs [ was: Bourne shell short-circuit operators improperly documented ]
Message-ID:  <200907281352.n6SDqXur017295@lurza.secnetix.de>
In-Reply-To: <4A6E3B17.7030609@emailrob.com>

next in thread | previous in thread | raw e-mail | index | archive | help

spellberg_robert <emailrob@emailrob.com> 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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200907281352.n6SDqXur017295>