Bash POSIX mode and ${var/PATTERN/STRING}

Bash POSIX mode and ${var/PATTERN/STRING}

am 09.01.2008 15:53:11 von Eze

Greetings,

Correct me if I am wrong, but the parameter expansion ${var/PATTERN/
STRING} (as well as ${var:OFFSET:LENGTH}) is not defined in the POSIX
specification [http://www.opengroup.org/onlinepubs/009695399/utilities/
xcu_chap02.html#tag_02_06_02]. I don't understand why running Bash
under POSIX mode [http://theory.uwinnipeg.ca/gnu/bash/bashref_66.html]
does not yield an error when such a substitution is used.

Thanks in advance for your help.

Best regards,

Ezequiel

Re: Bash POSIX mode and ${var/PATTERN/STRING}

am 09.01.2008 16:19:31 von Stephane CHAZELAS

On Wed, 9 Jan 2008 06:53:11 -0800 (PST), Eze wrote:
[...]
> Correct me if I am wrong, but the parameter expansion ${var/PATTERN/
> STRING} (as well as ${var:OFFSET:LENGTH}) is not defined in the POSIX
> specification [http://www.opengroup.org/onlinepubs/009695399/utilities/
> xcu_chap02.html#tag_02_06_02]. I don't understand why running Bash
> under POSIX mode [http://theory.uwinnipeg.ca/gnu/bash/bashref_66.html]
> does not yield an error when such a substitution is used.
[...]

bash --posix enables the POSIX mode of bash. That is bash will
interpret POSIX scripts the way it is specified by the POSIX
specification.

The ${var:OFFSET:LENGTH} syntax is not POSIX, so an interpreter
is allowed to behave however it wants, wether issuing a syntax
error message or playing a tune or behaving as bash does.

--
Stephane

Re: Bash POSIX mode and ${var/PATTERN/STRING}

am 09.01.2008 17:29:39 von Eze

Thanks Stephane,

My next question then is whether there is a shell that you would
recommend that adheres as closely as possible to POSIX (that is, POSIX
and nothing else) under a suitable mode.

Re: Bash POSIX mode and ${var/PATTERN/STRING}

am 09.01.2008 18:59:07 von Icarus Sparry

On Wed, 09 Jan 2008 08:29:39 -0800, Eze wrote:

> Thanks Stephane,
>
> My next question then is whether there is a shell that you would
> recommend that adheres as closely as possible to POSIX (that is, POSIX
> and nothing else) under a suitable mode.

A common answer is ash or dash.
http://gondor.apana.org.au/~herbert/dash/

Re: Bash POSIX mode and ${var/PATTERN/STRING}

am 10.01.2008 00:33:28 von Eze

Thanks to both of you.

Re: Bash POSIX mode and ${var/PATTERN/STRING}

am 10.01.2008 06:40:58 von Stephane CHAZELAS

On Wed, 9 Jan 2008 08:29:39 -0800 (PST), Eze wrote:
[...]
> My next question then is whether there is a shell that you would
> recommend that adheres as closely as possible to POSIX (that is, POSIX
> and nothing else) under a suitable mode.

See debian's posh (policy orientated shell). It's based on
pdksh, and the maintainers tried to remove the features that
were not POSIX.

--
Stephane