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

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
Eze [ Mi, 09 Januar 2008 15:53 ] [ ID #1903301 ]

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

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
Stephane CHAZELAS [ Mi, 09 Januar 2008 16:19 ] [ ID #1903303 ]

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

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.
Eze [ Mi, 09 Januar 2008 17:29 ] [ ID #1903305 ]

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

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/
Icarus Sparry [ Mi, 09 Januar 2008 18:59 ] [ ID #1903312 ]

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

Thanks to both of you.
Eze [ Do, 10 Januar 2008 00:33 ] [ ID #1904166 ]

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

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
Stephane CHAZELAS [ Do, 10 Januar 2008 06:40 ] [ ID #1904171 ]
Linux » comp.unix.shell » Bash POSIX mode and ${var/PATTERN/STRING}

Vorheriges Thema: how to test for user input
Nächstes Thema: How To Turn Off Auto Tab Complete?