Bug 46441 - /bin/sh does not do parameter expansion in PS1, PS2, PS4
Summary: /bin/sh does not do parameter expansion in PS1, PS2, PS4
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: standards (show other bugs)
Version: 5.0-CURRENT
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-standards (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-12-21 12:40 UTC by Jens Schweikhardt
Modified: 2018-05-28 19:42 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jens Schweikhardt freebsd_committer 2002-12-21 12:40:01 UTC
	If our /bin/sh is intended to support the SUSv3 User Portability
	(UP) option, it must do parameter expansion in PS[124]. If not,
    consider this PR null and void, even where prohibited. Quoting
	IEEE Std 1003.1-2001:

PS1

 Each time an interactive shell is ready to read a command, the value of
 this variable shall be subjected to parameter expansion and written to
 standard error. The default value shall be "$ " . For users who have
 specific additional implementation-defined privileges, the default may
 be another, implementation-defined value. The shell shall replace each
 instance of the character '!' in PS1 with the history file number of
 the next command to be typed. Escaping the '!' with another '!' (that
 is, "!!" ) shall place the literal character '!' in the prompt. This
 volume of IEEE Std 1003.1-2001 specifies the effects of the variable
 only for systems supporting the User Portability Utilities option.

PS2

 Each time the user enters a <newline> prior to completing a command
 line in an interactive shell, the value of this variable shall be
 subjected to parameter expansion and written to standard error. The
 default value is "> " . This volume of IEEE Std 1003.1-2001 specifies
 the effects of the variable only for systems supporting the User
 Portability Utilities option.

PS4

 When an execution trace ( set -x) is being performed in an interactive
 shell, before each line in the execution trace, the value of this
 variable shall be subjected to parameter expansion and written to
 standard error. The default value is "+ " . This volume of IEEE Std
 1003.1-2001 specifies the effects of the variable only for systems
 supporting the User Portability Utilities option.

PWD

 Set by the shell to be an absolute pathname of the current working
 directory, containing no components of type symbolic link, no
 components that are dot, and no components that are dot-dot when the
 shell is initialized. If an application sets or unsets the value of
 PWD, the behaviors of the cd and pwd utilities are unspecified.

How-To-Repeat: $ /bin/sh
$ PS1='$PWD >'
$PWD >cd /tmp                  <- should expand $PWD
$PWD >PS2='$PWD more:'
$PWD >foo ()
$PWD more:{
$PWD more:}
$PWD >PS4='$PWD -x : '
$PWD >set -x
$PWD >foo
+ foo                          <- PS4 seems hard coded to "+ "
Comment 1 Mike Barcroft freebsd_committer 2002-12-21 17:30:33 UTC
Responsible Changed
From-To: freebsd-standards->tjr

Over to tjr.
Comment 2 Tim Robbins freebsd_committer 2004-02-15 07:39:09 UTC
Responsible Changed
From-To: tjr->freebsd-bugs

Unassign due to lack of time and interest. Perhaps someone else 
will pick this up.
Comment 3 Stefan Farfeleder freebsd_committer 2005-12-26 18:41:24 UTC
Responsible Changed
From-To: freebsd-standards->stefanf

Grab.
Comment 4 Garrett Cooper 2011-01-29 20:46:43 UTC
    Technically the POSIX spec doesn't state that those must support
parameter expansion. Reiterating more recent text...

===============

ENV
    [UP XSI] [Option Start] The processing of the ENV shell variable
shall be supported on all XSI-conformant systems or if the system
supports the User Portability Utilities option. [Option End]

    This variable, when and only when an interactive shell is invoked,
shall be subjected to parameter expansion (see Parameter Expansion )
by the shell and the resulting value shall be used as a pathname of a
file containing shell commands to execute in the current environment.
The file need not be executable. If the expanded value of ENV is not
an absolute pathname, the results are unspecified. ENV shall be
ignored if the user's real and effective user IDs or real and
effective group IDs are different.

    ...

PS1
    Each time an interactive shell is ready to read a command, the
value of this variable shall be subjected to parameter expansion and
written to standard error. The default value shall be "$ " . For users
who have specific additional implementation-defined privileges, the
default may be another, implementation-defined value. The shell shall
replace each instance of the character '!' in PS1 with the history
file number of the next command to be typed. Escaping the '!' with
another '!' (that is, "!!" ) shall place the literal character '!' in
the prompt. This volume of POSIX.1-2008 specifies the effects of the
variable only for systems supporting the User Portability Utilities
option.

PS2
    Each time the user enters a <newline> prior to completing a
command line in an interactive shell, the value of this variable shall
be subjected to parameter expansion and written to standard error. The
default value is "> " . This volume of POSIX.1-2008 specifies the
effects of the variable only for systems supporting the User
Portability Utilities option.

PS4
    When an execution trace ( set -x) is being performed in an
interactive shell, before each line in the execution trace, the value
of this variable shall be subjected to parameter expansion and written
to standard error. The default value is "+ " . This volume of
POSIX.1-2008 specifies the effects of the variable only for systems
supporting the User Portability Utilities option.

===============

    Note that Parameter Expansion was explicitly mentioned in the
definition of ENV, but not in PS1, PS2, or PS4. I'm pretty sure that
bash expanding these variables is a `feature' of their shell and not
of the spec.
Thanks,
-Garrett
Comment 5 Jens Schweikhardt 2011-01-30 10:39:43 UTC
On Sat, Jan 29, 2011 at 12:46:43PM -0800, Garrett Cooper wrote:
#     Technically the POSIX spec doesn't state that those must support
# parameter expansion. Reiterating more recent text...
# 
# ===============
# 
# ENV
#     [UP XSI] [Option Start] The processing of the ENV shell variable
# shall be supported on all XSI-conformant systems or if the system
# supports the User Portability Utilities option. [Option End]
# 
#     This variable, when and only when an interactive shell is invoked,
# shall be subjected to parameter expansion (see Parameter Expansion )
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# by the shell and the resulting value shall be used as a pathname of a
# file containing shell commands to execute in the current environment.
# The file need not be executable. If the expanded value of ENV is not
# an absolute pathname, the results are unspecified. ENV shall be
# ignored if the user's real and effective user IDs or real and
# effective group IDs are different.
# 
#     ...
# 
# PS1
#     Each time an interactive shell is ready to read a command, the
# value of this variable shall be subjected to parameter expansion and
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# written to standard error. The default value shall be "$ " . For users
# who have specific additional implementation-defined privileges, the
# default may be another, implementation-defined value. The shell shall
# replace each instance of the character '!' in PS1 with the history
# file number of the next command to be typed. Escaping the '!' with
# another '!' (that is, "!!" ) shall place the literal character '!' in
# the prompt. This volume of POSIX.1-2008 specifies the effects of the
# variable only for systems supporting the User Portability Utilities
# option.
# 
# PS2
#     Each time the user enters a <newline> prior to completing a
# command line in an interactive shell, the value of this variable shall
# be subjected to parameter expansion and written to standard error. The
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# default value is "> " . This volume of POSIX.1-2008 specifies the
# effects of the variable only for systems supporting the User
# Portability Utilities option.
# 
# PS4
#     When an execution trace ( set -x) is being performed in an
# interactive shell, before each line in the execution trace, the value
# of this variable shall be subjected to parameter expansion and written
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# to standard error. The default value is "+ " . This volume of
# POSIX.1-2008 specifies the effects of the variable only for systems
# supporting the User Portability Utilities option.
# 
# ===============
# 
#     Note that Parameter Expansion was explicitly mentioned in the
# definition of ENV, but not in PS1, PS2, or PS4. I'm pretty sure that
# bash expanding these variables is a `feature' of their shell and not
# of the spec.

My reading is that parameter expansion is mentioned for all of them.
Am I missing something?


Regards,

	Jens
-- 
Jens Schweikhardt http://www.schweikhardt.net/
SIGSIG -- signature too long (core dumped)
Comment 6 Garrett Cooper 2011-01-30 20:08:13 UTC
On Sun, Jan 30, 2011 at 2:39 AM, Jens Schweikhardt
<schweikh@schweikhardt.net> wrote:
> On Sat, Jan 29, 2011 at 12:46:43PM -0800, Garrett Cooper wrote:
> # =A0 =A0 Technically the POSIX spec doesn't state that those must suppor=
t
> # parameter expansion. Reiterating more recent text...
> #
> # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> #
> # ENV
> # =A0 =A0 [UP XSI] [Option Start] The processing of the ENV shell variabl=
e
> # shall be supported on all XSI-conformant systems or if the system
> # supports the User Portability Utilities option. [Option End]
> #
> # =A0 =A0 This variable, when and only when an interactive shell is invok=
ed,
> # shall be subjected to parameter expansion (see Parameter Expansion )
> =A0^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> # by the shell and the resulting value shall be used as a pathname of a
> # file containing shell commands to execute in the current environment.
> # The file need not be executable. If the expanded value of ENV is not
> # an absolute pathname, the results are unspecified. ENV shall be
> # ignored if the user's real and effective user IDs or real and
> # effective group IDs are different.
> #
> # =A0 =A0 ...
> #
> # PS1
> # =A0 =A0 Each time an interactive shell is ready to read a command, the
> # value of this variable shall be subjected to parameter expansion and
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ^^^^^^^^^^^^^^^^^^^^^^^^^=
^^^^^^^^^^^^^^^^
> # written to standard error. The default value shall be "$ " . For users
> # who have specific additional implementation-defined privileges, the
> # default may be another, implementation-defined value. The shell shall
> # replace each instance of the character '!' in PS1 with the history
> # file number of the next command to be typed. Escaping the '!' with
> # another '!' (that is, "!!" ) shall place the literal character '!' in
> # the prompt. This volume of POSIX.1-2008 specifies the effects of the
> # variable only for systems supporting the User Portability Utilities
> # option.
> #
> # PS2
> # =A0 =A0 Each time the user enters a <newline> prior to completing a
> # command line in an interactive shell, the value of this variable shall
> # be subjected to parameter expansion and written to standard error. The
> =A0^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> # default value is "> " . This volume of POSIX.1-2008 specifies the
> # effects of the variable only for systems supporting the User
> # Portability Utilities option.
> #
> # PS4
> # =A0 =A0 When an execution trace ( set -x) is being performed in an
> # interactive shell, before each line in the execution trace, the value
> # of this variable shall be subjected to parameter expansion and written
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^=
^^^^
> # to standard error. The default value is "+ " . This volume of
> # POSIX.1-2008 specifies the effects of the variable only for systems
> # supporting the User Portability Utilities option.
> #
> # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> #
> # =A0 =A0 Note that Parameter Expansion was explicitly mentioned in the
> # definition of ENV, but not in PS1, PS2, or PS4. I'm pretty sure that
> # bash expanding these variables is a `feature' of their shell and not
> # of the spec.
>
> My reading is that parameter expansion is mentioned for all of them.
> Am I missing something?

Jilles noted I was wrong (I was being lazy when reading the text and
was only looking for the Parameter Expansion link).

There are several issues with parameter expansion comparing dash to FreeBSD=
 ash.

Thanks for the correction,
-Garrett
Comment 7 Stefan Farfeleder freebsd_committer 2015-01-17 08:59:08 UTC
I'm not working on /bin/sh anymore.
Comment 8 Eitan Adler freebsd_committer freebsd_triage 2018-05-28 19:42:56 UTC
batch change:

For bugs that match the following
-  Status Is In progress 
AND
- Untouched since 2018-01-01.
AND
- Affects Base System OR Documentation

DO:

Reset to open status.


Note:
I did a quick pass but if you are getting this email it might be worthwhile to double check to see if this bug ought to be closed.