[TUHS] A few comments on porting the Bourne shell

Warner Losh imp at bsdimp.com
Tue Jan 3 05:50:47 AEST 2023


On Mon, Jan 2, 2023, 11:18 AM Clem Cole <clemc at ccc.com> wrote:

>
>
> On Mon, Jan 2, 2023 at 1:13 PM Larry McVoy <lm at mcvoy.com> wrote:
>
>>
>> My scripts worked with /bin/sh being whatever it was.
>>
>> It's interesting to me that other old timers, like Clem, are saying
>> exactly the same thing as I am.  Are we all wrong?
>>
> Exactly -- if you are disciplined -- it just works.  It's not magic.
>

I've only got 30 years experience in writing portable shell scripts... But
I have a slightly different take. There is an element of luck involved.
There are a number of constructs that are valid in v7 shell that aren't
completely portable due to bugs in vendor shells. The luck part comes in
either you know what to avoid because you got unlucky and got burned in the
past. Or you got lucky and never thought to write something like that so it
just works. With experience, you know what works...

I notice the old timers hedged a little bit by saying things like
"virtually all" so maybe they had a bit of bad luck now and again...

Also, the really aweful systems are rare enough today that most folks on
this list have had the good luck not to need to run on them... :)

You can get super close though, but I'll bet there's some scripts that work
only because they didn't run on, say, Eunice...

But luck favors the prepared... and making the effort to try to be portable
will help when you have to run on dash, or one of the BSD shells that might
not have $<(cmd) or some other useful but not universal feature...

Warner

>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://minnie.tuhs.org/pipermail/tuhs/attachments/20230102/b1e19324/attachment.htm>


More information about the TUHS mailing list