bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Behavior of ${var/*/text} has changed


From: Eric Pruitt
Subject: Re: Behavior of ${var/*/text} has changed
Date: Fri, 16 Sep 2016 12:30:59 -0700
User-agent: Mutt/1.5.23 (2014-03-12)

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/?*/address@hidden:}\\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.

Eric



reply via email to

[Prev in Thread] Current Thread [Next in Thread]