Austin Group Defect Tracker

Aardvark Mark IV

Viewing Issue Simple Details Jump to Notes ] Issue History ] Print ]
ID Category Severity Type Date Submitted Last Update
0001478 [Issue 8 drafts] Shell and Utilities Editorial Clarification Requested 2021-05-23 16:12 2021-05-23 16:16
Reporter stephane View Status public  
Assigned To
Priority normal Resolution Open  
Status New   Product Version Draft 2
Name St├ęphane Chazelas
User Reference
Section 2.6.2 Parameter Expansion
Page Number 2318-2320
Line Number
Final Accepted Text
Summary 0001478: clarify ${@?error}, ${@+set}, "${@+set}", "${*+set}"... etc. expansions
Description While the spec does leave expansions of ${@#pattern} (and variants with ##, %, %%) unspecified, or that $@/$* expansion shall not cause the shell to exit when the nounset option is set (without going as far as saying that $@ / $* should be considered always set), it leaves it quite unclear what the expansion of

${@?error} "${@?error}", ${@+"$@" more}, "${*-foo}", "${@:+foo}", ${*+foo} should yield.

In practice, there is a lot of variation in behaviour between implementations, with some implementations considering $@/$* "set" always (like for set -u) or only if $# > 0. Or "$*" "non-empty" only if $1 is non empty or some only if "$*" would yield a non-empty string (with variations in behaviour if $IFS is empty), etc. For some ${@?error} is a syntax error, etc.

Some shells with array support try to be consistent with their handling of $@ compared to that of other arrays, but in different ways as their arrays take different shapes, etc.

The only portable variants I've managed to find were: "${*-foo}" and "${*+foo}" which expand to foo (resp. "$*") if and only if $# == 0, which is not among the most useful ones.
Desired Action Leaving the expansion of all those - + ? :- :+ :? operators unspecified for the @ and * parameters seems like the least bad option.

Alternatives are likely to either make things more confusing or break some shells backward compatibility.

Users can always spell things out like:

if [ "$#" -eq 0 ]; then

or if:

if [ -n "$*" ]; then

Tags No tags attached.
Attached Files

- Relationships

-  Notes
stephane (reporter)
2021-05-23 16:16

For the record, this came to my attention at [^]

Where someone posted this:

#!/bin/sh -

wc -l -- "${@?expected to get filename argument(s)}"

code which in practice is not portable, and for which I'm not sure what the POSIX spec currently says.

- Issue History
Date Modified Username Field Change
2021-05-23 16:12 stephane New Issue
2021-05-23 16:12 stephane Name => St├ęphane Chazelas
2021-05-23 16:12 stephane Section => 2.6.2 Parameter Expansion
2021-05-23 16:12 stephane Page Number => 2318-2320
2021-05-23 16:16 stephane Note Added: 0005365

Mantis 1.1.6[^]
Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker