Re: T/F var expansion?

2019-07-29 Thread Stephane Chazelas
2019-07-28 21:17:43 -0700, L A Walsh:
> Is there a T/F var expansion that does:
>  
> var=${tst:+$yes}${tst:-$no}
> 
> but with yes/no in 1 expansion?
[...]

You can also do:

no_yes=(no yes)
echo "${no_yes[${var+1}]}"

For the reverse:

echo "${no_yes[!0${var+1}]}"

See also:

map=(unset empty non-empty)
echo "${map[${var+1}+0${var:+1}]}"

-- 
Stephane




Re: T/F var expansion?

2019-07-29 Thread David
On Mon, 29 Jul 2019 at 14:18, L A Walsh  wrote:
>
> Is there a T/F var expansion that does:

[...]

>
> Sorry if this is already implemented in some form, I'm just
> not remembering there being one.

Your message is not a bug report. The list
  help-b...@gnu.org>
exists to help with questions like this.



Re: T/F var expansion?

2019-07-29 Thread L A Walsh



On 2019/07/28 22:01, Martin Schulte wrote:
> Hello!
>   
>> Is there a T/F var expansion that does:
>> var=${tst:+$yes}${tst:-$no}
>> but with yes/no in 1 expansion?
>> 
>
> At least if you are only working with numbers you can use
> ((var=(tst!=0?42:31)))
> But is this a question for bug-bash?
> Best regards,
> Martin
>   

I'm familiar with the numeric form, and many times have lamented the
lack of a similar form for non-numeric data.

The fact that bash provides such a feature for numbers but not
for strings, seems like a missing feature. Depending on whether or
not you expected or wanted a language to provide similar operators for
the various types of data it can process such a deficit might be felt
to be a sufficient problem to warrant a solution. Wouldn't it be
the case that the lack of such a feature became a "type" of bug
that required, to the extent it was wanted,  a "fix"? 

That said, I'm pretty sure that ideas for bash don't have to be
existing bugs in order to be considered something that might qualify
for a code addition or update.

-l





Re: T/F var expansion?

2019-07-28 Thread Martin Schulte
Hello!

> Is there a T/F var expansion that does:
>  
> var=${tst:+$yes}${tst:-$no}
> 
> but with yes/no in 1 expansion?

At least if you are only working with numbers you can use

((var=(tst!=0?42:31)))

But is this a question for bug-bash?

Best regards,

Martin



T/F var expansion?

2019-07-28 Thread L A Walsh
Is there a T/F var expansion that does:
 
var=${tst:+$yes}${tst:-$no}

but with yes/no in 1 expansion?

Something like:

var=${tst:^yes^no}
  |   |
  \___\___ or some other char(s)

with the opposite syntax being allowed as

var=${!tst:^no^yes}

(or) if '!' before the varname is unwieldy:

 var=${tst:!no!yes}


Obviously the 1 code-snippet solves the problem, but looks
a bit redundant, at the least...

Sorry if this is already implemented in some form, I'm just
not remembering there being one.