[Top][All Lists]

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

Re: ${b+s ''}

From: Greg Wooledge
Subject: Re: ${b+s ''}
Date: Tue, 19 Feb 2019 10:41:41 -0500
User-agent: NeoMutt/20170113 (1.7.2)

On Sun, Feb 17, 2019 at 08:07:06PM -0500, Chet Ramey wrote:
> On 2/16/19 11:38 AM, address@hidden wrote:
> > I would like to include a null string as part of a parameter expansion word:
> > 
> >> mapfile -t${bNullDelimited+d ''}
> > 
> > When bNullDelimited is set, I expect this to expand to:
> > 
> >> mapfile -td ''
> > 
> > However, it expands to:
> > 
> >> mapfile -td
> There are mixed behaviors. The idea behind the bash behavior is that a
> null string added to a non-empty word is simply discarded, and this happens
> while the word after the `+' is being processed, before word splitting.
> bash/ksh93/zsh do it one way, ash-derived shells/mksh/yash do it another.

Ugh.  Shells are so messy.

wooledg:~$ ksh
$ args ${PATH+d ''}
1 args: <d>

wooledg:~$ dash
$ args ${PATH+d ''}
2 args: <d> <>

Looks like the best workaround (for bash/ksh) is to store the -d '' args
in an array, and use something like:

mapfile -t ${bNullDelimited+"address@hidden"}

This works in both ksh and bash; I did not test anything else (and of
course dash and other close-to-POSIX shells don't even *have* arrays, so
it's a good thing the workaround isn't needed there).

Then again, mapfile is bash-only, so you probably aren't looking for a
great level of portability here.

reply via email to

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