Re: POSIX on $()
- From: Stephane CHAZELAS <stephane_chazelas@xxxxxxxx>
- Date: Thu, 23 Apr 2009 09:29:21 +0000 (UTC)
2009-04-23, 09:18(+00), Daniel Chicayban Bastos:
(*) POSIX $()
POSIX's ``Shell & Utilities'' on section ``2.6 Word Expansions'' states
The '$' character is used to introduce parameter expansion, command
substitution, or arithmetic evaluation. If an unquoted '$' is
followed by a character that is either not numeric, [not]
the name of one of the special parameters (see Special
Parameters), [not] a valid first character of a variable
name, [not] a left curly brace ( '{' ) or a left
parenthesis, the result is unspecified.
So, is it the case that
#!/bin/sh
tmp=$(tempfile)
is implementation dependent?
It's true the wording is unclear, I've added a few [not] above
to help clarify.
But applying a bit of common sense, $ is followed by (, so it is
specified, it is a command substitution. What is unspecified as
per POSIX, is what happens when the file starts with "#!" or the
output of "tempfile" as that's not a command specified by POSIX.
[...]
When I say ``man sh,'' I really am reading bash's manual page. What do
you advise if my intention to write POSIX's /bin/sh conformant
programs? For instance, what documentation should I read, even if I
can't wholly rely on it?
bash is a POSIX conformant shell when called as sh. Its manual
describes bash, not the POSIX sh syntax which is a subset of the
syntax recognised by bash. Just like gcc is a C compiler, don't
expect to know how to write portable C code by reading gcc
manual. If you want to learn how to write conformant *scripts*,
read the POSIX specification.
--
Stéphane
.
- Follow-Ups:
- Re: POSIX on $()
- From: Daniel Chicayban Bastos
- Re: POSIX on $()
- References:
- POSIX on $()
- From: Daniel Chicayban Bastos
- POSIX on $()
- Prev by Date: Re: Timed event
- Next by Date: sed not matching "("
- Previous by thread: POSIX on $()
- Next by thread: Re: POSIX on $()
- Index(es):
Relevant Pages
|