On Fri, Sep 16, 2016 at 03:22:29PM -0400, Greg Wooledge wrote:
> Off hand I'd say the bash 4.4 behavior is correct.  * matches 0 or
> more characters, so it should match an empty or undefined variable.

Yes, I agree that the Bash 4.4 behavior is more reasonable, but I think
the change at least needs to be documented (assuming I didn't miss it).

> > Fix:
> >     As a work-around, I have changed the expressions I'm using from
> >     ${VAR/*/...} to ${VAR/?*/...}.
> That, or ${VAR:+not empty} which is how I suggest testing for variable
> set-and-not-empty-ness.

I'm aware of that construct, but that doesn't do what I want unless I'm
missing something; I don't want to change the value of the variable.
Here's an example from my prompt command:

    function prompt-command()
        # [...]

        local jobs="$(jobs)"

        # [...]

        PS1="${SSH_TTY/?*/\\u@\\h:}\\W${jobs/?*/ [\\j]}\\$ "

        # [...]

In this example, I want to show the username and hostname if SSH_TTY is
set and not empty, but I do not want to modify its value. I am also
showing the number of jobs in brackets, but I only want to do that if
there are some jobs in the background.


Reply via email to