Re: POSIX on $()



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
.



Relevant Pages

  • Re: POSIX on $()
    ... The '$' character is used to introduce parameter expansion, command ... it is a command substitution. ... output of "tempfile" as that's not a command specified by POSIX. ...
    (comp.unix.programmer)
  • Re: Inserting a character in certain column
    ... I need to insert a character in certain column in all rows of the file ... or use a regexp substitution. ... Here a more detailed explanation of the command: ... line that matched the regular expression) ...
    (Ubuntu)
  • Re: ask help about expect
    ... how many times substitution occurs, but I think (judging by what I ... think the programmer intends) the code tries to match the character ... executed when the pattern matches. ... character as the first word of a command-line or command string, ...
    (comp.lang.tcl)
  • Re: DCL question (of the day)- null byte in string symbol
    ... The string isn't that long. ... Note that is 7 bits of the second character, 8 bits of ... Lexical substitution is a possibility. ... The fact that command verification reflects a truncated command line ...
    (comp.os.vms)
  • vi editor FAQ (Frequently Asked Question List), Part 2/2
    ... has the UCB distribution of vi, and lots of useful macros. ... m0 is the ex command to move the line to line 0. ... Swap character and one vertically above: ... A non-visual editor under Unix. ...
    (comp.unix.questions)