Path: csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail From: L A Walsh Newsgroups: gnu.bash.bug Subject: Re: null array[*] expansion not treated as null Date: Sun, 25 Nov 2018 12:02:41 -0800 Lines: 68 Approved: bug-bash@gnu.org Message-ID: References: NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Trace: usenet.stanford.edu 1543176178 1047 208.118.235.17 (25 Nov 2018 20:02:58 GMT) X-Complaints-To: action@cs.stanford.edu Cc: bug-bash To: Grisha Levit Envelope-to: bug-bash@gnu.org User-Agent: Thunderbird In-Reply-To: X-MIME-Autoconverted: from 8bit to quoted-printable by Ishtar.sc.tlinx.org id wAPK2fHn019513 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 173.164.175.65 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com gnu.bash.bug:14853 On 11/12/2018 1:32 PM, Grisha Levit wrote: > When an array A has non-zero elements but the expansion of "${A[*]}" is > still > a null string, it is not treated as such for purposes of ${var:-X} expa= nsion > (though $* is treated as null in the same circumstance). > > $ A=3D(''); set -- '' > $ echo "<${A[*]:-X}>" "<${*:-X}>" > <> > =20 ---- Ah, a null string !=3D empty. Example: > A=3D() > declare -p A declare -a A=3D() > A=3D('') #null string > declare -p A declare -a A=3D([0]=3D"") #a string is still a string, even if empty Related: FWIW, below, "IFS=3D" sets IFS to an empty string, like IFS=3D'' > $ IFS=3D > $ A=3D('' ''); set -- '' ''; > =20 Typing in lines to echo the size of A and shell params: > echo "=3D$#" ; echo number of parameters set by "set - '' ''" =3D2 > echo "size of A=3D${#A[@]}" size of A=3D2 > $ echo "<${A[*]:-X}>" "<${*:-X}>" > <> > =20 --- Going to use "=C2=AB=C2=BB" instead of "<>" cuz <> are shell chars th= at need quoting ( otherwise: bash: syntax error near unexpected token `<' = ). First, your echo: > echo "=C2=AB${A[*]:-X}=C2=BB" "=C2=AB${*:-X}=C2=BB" =20 =C2=AB=C2=BB =C2=ABX=C2=BB (#same) and w/o the quotes: > echo =C2=AB${A[*]:-X}=C2=BB =C2=AB${*:-X}=C2=BB =C2=AB =C2=BB =C2=AB =C2=BB --- Notice adding quotes around your vars can change what is echo'ed. Looks like the output-separator ' ' (space) is embedded in the '*'s of both expressions, but [*] undergoes expansion, while the 2nd one doesn't. So 1 hint to remember a variable is an internally quoted entity, such if it is assigned to another var, it will be assigned "as-is", but if you put double-quotes around a variable, it will replace sequences of white space with 1 white space. Does that address your examples' behaviors? of some sort where '*'=C2=AB=C2=BB