[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: handling of test == by BASH's POSIX mode

From: Dan Douglas
Subject: Re: handling of test == by BASH's POSIX mode
Date: Sun, 27 May 2012 11:08:38 -0500
User-agent: KMail/4.8.3 (Linux/3.4.1-pf+; KDE/4.8.3; x86_64; ; )

> POSIX hasn't provided a way to validate whether a script
> only uses features that are required to be supported by POSIX
> compliant interpreters.

I believe that was someone else's point, but yes that would be a problem for 
anyone who wanted to implement compliance check warnings.

> even if bash is technically compliant with POSIX, what use case is usefully 
> served by having bash support a superset of the POSIX test operators while 
executing in POSIX mode?

It's a matter of practicality and the fact that nobody has written it yet. If 
you wanted to implement conformance checks without making Bash even bigger and 
slower, and harder to maintain, I don't think there would be objections. Bash 
just modifies conflicting features to the minimal extent necessary to bring it 
into compliance, which seems to be the path of least resistance.

This would be a big job, I think, and not quite at the top of my wish-list. 
Right now you can increase the number of things that fail by explicitly 
disabling non-POSIX built-ins using the Bash "enable" builtin.

> I wasn't claiming that static checking would be viable. In fact, the
> impossibility of static checking is precisely why it would be useful
> to have real POSIX "compliant" interpreters that were as conservative
> as possible in the syntax and commands they accepted at least in their
> so-called POSIX mode.

Dash is useful for testing. The Bash answer is [[, which CAN do a lot of 
special error handling on due to it being a compound command. I wrote a bit 
about this here:


In reality, [[ is one of the very most portable non-POSIX features available. 
Most people shouldn't have to worry about avoiding it.

On Sunday, May 27, 2012 11:09:03 PM Jon Seymour wrote:
> That said, from the point of view of promoting interoperable scripts,
> my view is that it (in an ideal world**) would be better if bash chose
> to fail, while executing in POSIX mode, in this case.

In an ideal world, POSIX would define [[, Dash wouldn't exist, and we would 
have some resource other than POSIX that specifies what's ACTUALLY portable 
between modern shells, so that the only people who have to worry are those 
targeting Busybox and Solaris Heirloom, or stubborn curmudgeons who insist on 
Dash... some of these things feel like supporting IE6 - it's better to just 

> This is exactly my problem: I replaced /bin/sh -> dash with /bin/sh ->
> bash because a 3rd party product installation script failed when dash
> was the "POSIX" shell.

If you need a fast small shell, use mksh. It supports some of the more 
essential features of both Bash and Ksh (arrays, ((, [[), and some of its own, 
without all the draconian restrictions of dash.

(Note this is querying my package manager, including symbols and source files)

# equery s dash
 * app-shells/dash-
         Total files : 73
         Total size  : 1.14 MiB
 # equery s mksh
 * app-shells/mksh-9999
         Total files : 39
         Total size  : 1.61 MiB
 # equery s bash
 * app-shells/bash-4.2_p28
         Total files : 464
         Total size  : 6.33 MiB

Dan Douglas

Attachment: signature.asc
Description: This is a digitally signed message part.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]