View Issue Details

IDProjectCategoryView StatusLast Update
00012721003.1(2016/18)/Issue7+TC2Shell and Utilitiespublic2024-06-11 09:08
Reporterstephane Assigned To 
PrioritynormalSeverityObjectionTypeError
Status ClosedResolutionAccepted As Marked 
NameStephane Chazelas
Organization
User Reference
Sectioncolon special utility
Page Number2388 (in 2018 edition)
Line Number
Interp Status---
Final Accepted Text0001272:0004523
Summary0001272: colon doesn't "expand its arguments" and must not process options
DescriptionThe colon special utility specification says:

> This utility shall only expand command arguments.

That is not true. ":" doesn't do anything with its arguments.

I beleive what that text meant was that ":" is a special builtin
as any other and not a comment introducing token in the shell
syntax contrary to "#", so that what follows is subject to all
expansions.

For instance that in:

: "$((a = 1))" /*/*/*/*

Those arithmetic and pathname expansions and their side effects
are still performed before the ":" utility is invoked.

But what the ":" utility gets as arguments is the result of
those expansions, and it doesn't do anything with them.

Also, it says "OPTIONS: None". But that would still mean that
implementations are free to support some as extensions. Worse,
since ":" is a special builtin, that means that implementations
are not required to support "--" as an end-of-option marker.

Yet, as demonstrated in the (broken, see below) first example,
things like:

: "${X=abc}"

are a common idiom.

In the current version of the spec however, that produces
unspecified results unless $X can be guaranteed not to start
with a "-" (and : -- "${X=abc}" doesn't fix it).

I don't know of any shell implementation whose ":" handles
options. Even ksh93 where most builtins support common
--help/--man/--author options doesn't do it for ":".

POSIX should make it clear that no option processing should be
done, that all the arguments are to be ignored.

The first example:

> : ${X=abc}
> if false
> then :
> else echo $X
> fi


has a few poor shell coding practice instances/bugs:

- missing quotes around expansions
- usage of echo for arbitrary data
Desired ActionChange the DESCRIPTION to:

This utility shall do nothing and return with a 0 exit status.

Change OPTIONS to:

The null utility shall not process any option. All arguments
shall be ignored whether they start with "-" or not.

If deemed necessary, add an "APPLICATION USAGE" section
clarifying that ":" differs from "#" in that it's a command and
not a token in the shell syntax. And that it differs from "true"
in that it's a special utility, accepts arguments that it
ignores and doesn't process options (that's also the case of
most true implementations but not all).

Change the first example to:

: "${X=abc}"
if     false
then   :
else   printf '%s\n' "$X"
fi


On an unrelated note, as it's very unintuitive, it may be worth
also adding to the second example description as a reminder:
"colon being a special utility, if the z file cannot be opened,
it shall cause the shell to exit".
Tagstc3-2008

Activities

geoffclare

2019-08-15 16:15

manager   bugnote:0004523

On page 2389 line 76434 section 2.14 colon, change:
This utility shall only expand command arguments.
to:
This utility shall do nothing except return a 0 exit status.

On page 2389 line 76437 section 2.14 colon, change OPTIONS from:
None.
to:
This utility shall not recognize the "--" argument in the manner specified by Guideline 10 of [xref to XBD 12.2]. Implementations shall not support any options.

On page 2389 line 76451 section 2.14 colon, change STDERR from:
The standard error shall be used only for diagnostic messages.
to:
Not used.

On page 2389 line 76459 section 2.14 colon, change CONSEQUENCES OF ERRORS from:
Default.
to:
None.

On page 2389 line 76463 section 2.14 colon, change the first example to:
: "${X=abc}"
if     false
then   :
else   printf '%s\n' "$X"
fi
abc

On page 2390 line 76472 section 2.14 colon, change:
... and creates or truncates file z.
to:
... and creates or truncates file z; if the file cannot be created or truncated, a non-interactive shell exits (see [xref to 2.8.1]).

Issue History

Date Modified Username Field Change
2019-07-24 20:34 stephane New Issue
2019-07-24 20:34 stephane Name => Stephane Chazelas
2019-07-24 20:34 stephane Section => colon special utility
2019-07-24 20:34 stephane Page Number => 2388 (in 2018 edition)
2019-08-15 16:15 geoffclare Note Added: 0004523
2019-08-15 16:16 geoffclare Interp Status => ---
2019-08-15 16:16 geoffclare Final Accepted Text => 0001272:0004523
2019-08-15 16:16 geoffclare Status New => Resolved
2019-08-15 16:16 geoffclare Resolution Open => Accepted As Marked
2019-08-15 16:16 geoffclare Tag Attached: tc3-2008
2019-11-20 16:15 geoffclare Status Resolved => Applied
2024-06-11 09:08 agadmin Status Applied => Closed