[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Behavior of ${var/*/text} has changed
From: |
Greg Wooledge |
Subject: |
Re: Behavior of ${var/*/text} has changed |
Date: |
Fri, 16 Sep 2016 15:38:04 -0400 |
User-agent: |
Mutt/1.4.2.3i |
On Fri, Sep 16, 2016 at 12:30:59PM -0700, Eric Pruitt wrote:
> 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.
You're confusing :+ with :=
imadev:~$ echo "$BASH_VERSION"
4.4.0(1)-release
imadev:~$ unset undefined; defined=yes; empty=
imadev:~$ echo "<${undefined:+a}> <${defined:+b}> <${empty:+c}>"
<> <b> <>
imadev:~$ echo "<${undefined+a}> <${defined+b}> <${empty+c}>"
<> <b> <c>
imadev:~$ declare -p undefined defined empty
bash: declare: undefined: not found
declare -- defined="yes"
declare -- empty=""
Re: Behavior of ${var/*/text} has changed, Chet Ramey, 2016/09/17