From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id 124EB246F5 for ; Thu, 18 Apr 2024 00:14:22 +0200 (CEST) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1713392062; b=XXp0TwIVgzQUh/qWaahkbcjkpHLf3TOisIlzH+W6KZZaneEUUajza08HwHuZm5lPWQ4PS2XOse xaCia8qxz+oKwt7l5+Cs8V/gCccIN+OQ4hLAt05yS4ZaeP70kkd853Z4H7KprnkNy/cqNPdsDX MpbMfNJWd0OJyzZ3oqJakx6V/zk1DKcy7qyGwYRyiq+sQh723O1H705iUMOtDCxMJ58hQF+TCU obu+wVrxBH9rUNLerAE/5c6EBiSxvgpwf3xUhn+p71ufaMFK7ITHHWVa0K9FPQyZk4q7V4IgnK ygLdstGAqwsWsPpjKE/55te2ffDdSB5zStPETp0O72rF7w==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lf1-f42.google.com) smtp.remote-ip=209.85.167.42; dkim=pass header.d=brasslantern-com.20230601.gappssmtp.com header.s=20230601 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1713392062; bh=fEthB978KoFX3NXV4wTYJ4UTpBGtemII0owECd8Ao8M=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=RxBEnMg3K0aaSgdHpDGf+q7Y988TNuidMewZXeiTriA/lCV1A4HKjBUrbPKhvYEqCVTzaEoPld mssILXkUFtxvQ49rtZJo3/bJz/PDdacBVYJ596ulffzx+A9gmd9R3/Wz7YvFcHgwn9j5kBkOr3 ZmWcnmhB8HowJ3pAGN+1tlHcLo4hKWF7mw/Mefh/pUQPCTkIvYhFZ/ElreMt/l12TBeB6Pb8t4 TtUajAvzWtG1yd9nVMx7m9fmblF0CI82v9D1IgtLte8venHT/AJCToto58k+lNlwrEy2bvIx6g oYN+WoJ6Nrmz0ATDu4lGUqdshP9AJ3IYb0k4m3rgoX6Wxg==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=2P4T9TNkOmoTiUr3osFCyYawV2ey27hXbL+q9jefdG0=; b=AIJpofhtQWPfeBXgT15Z9Z0cbD caO1EuyTckzY+J0m9YQlA0ohOGVlp7gvOmZl1jHYWWcwGUUyMg8lWrVxeyqp3PcTfSnxHknxAzUkX l1obv6h5MFEBR/Nvn2nuTV5uXOgnFOV/Tz7zItYJ2aJECtZTlFa1shw2WWR5are+vXmga8AJvub7V kp/OQr+JdjKdHP7HX47yUzRbtEpsQesjoOlrnQaJo5c+fqKTdqX/zzmfzhhRTwl3i4sQXF610GwZC VrfKSndVs9wL68vbM1z0/cJSL1YW0KSg0lAPM/c8oQ8SgExwLpCI2t4UJuXOj2rjPoQbZgNKA7ZX7 +LkMTuDA==; Received: by zero.zsh.org with local id 1rxDXq-000KhP-14; Wed, 17 Apr 2024 22:14:22 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lf1-f42.google.com) smtp.remote-ip=209.85.167.42; dkim=pass header.d=brasslantern-com.20230601.gappssmtp.com header.s=20230601 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-lf1-f42.google.com ([209.85.167.42]:52593) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1rxDXD-000KMt-N0; Wed, 17 Apr 2024 22:13:45 +0000 Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-518e2283bd3so204946e87.1 for ; Wed, 17 Apr 2024 15:13:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20230601.gappssmtp.com; s=20230601; t=1713392023; x=1713996823; darn=zsh.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=2P4T9TNkOmoTiUr3osFCyYawV2ey27hXbL+q9jefdG0=; b=lDt7h4ITtcig+WAo4Jnity3OAe6LZlFiGzcZfLHrV+dx08fbBKgLAx6uKIJa9EhGtp tX4tRs6V5Fyxzgsf/EQxLh/Q24oyTaz6MPnXNtLIon3/pgveMnuOW1iKxJvk4lIiufPA 8B5TjaAiFUYJseHNerrIQF+H1CpKfsHK63rDueUEiywlvZgvgYnxDUi6KJZkpn3AeF58 g3priEH2qV/9oehJRAncZzqTMZcc4QfxeSjRNTNfm5sSzOzKYqMHHUL2awX+ZE/1dUCm 7FVw/QKjlMKK1PEYMxKVuEOIEEhwT1qp8i+ZgVr6LW6F6ih6JqWHz0O6dbaByzWz1Xg3 71MQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713392023; x=1713996823; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=2P4T9TNkOmoTiUr3osFCyYawV2ey27hXbL+q9jefdG0=; b=GxI+haE0B0N6EaCQMN2q2Jsc7t+vFZmbKWfg2Pkiis8WeFCZGXw91jSeZ07myuyrMZ nWmv3A1pqJq+TTcCXPYRpcTrqvu05Laseh4iqsjtX7Ys/fdMn2jXe8yRBs0ry8edsD0K KP38XrW+rkB8roF8/YM1Kp/uy+oMkG3+I5hUgNivhjDjXS9tA3+haAZnjbzwmmyEFyY0 AEOFAvaCa8YLFQYiUf5qx2TgUEhdfCnZbJrY1/VzofOS8v7cI4kog3iSN2LeV9YWS81n NYu00TSBJwJNK5HvJIbo/XoIsQ+fZXL9xmMhbAoWY+D434A63mlLETkFarWP93vrWUK3 +++Q== X-Gm-Message-State: AOJu0Ywjc15yeDPRE7c/4DsGRS7wTKjSbhjp9sNWvLExPNbkngmqQ9Sf hzOXZEZvY+fYEEs7M+xsxekPQAjGEJoEAbY42Yty7R3EKoFOsk8FMDG1olLoAm5BefHZrplkkPm +2TCdrQnloA2BKJgniPWaLLbmCsVbCFqll7+Z X-Google-Smtp-Source: AGHT+IGOM3ovEFgUqal/l2YDSeVcAbR1nVoo12u7AnyM47u4XhK8/VzLfVBnRAsz51KWSMPCyaptgG5MXJCC9cKkOcI= X-Received: by 2002:ac2:5928:0:b0:516:cdfa:1802 with SMTP id v8-20020ac25928000000b00516cdfa1802mr332730lfi.63.1713392022632; Wed, 17 Apr 2024 15:13:42 -0700 (PDT) MIME-Version: 1.0 References: <143C3C91-0198-4D62-8B81-9830CA7DB649@gmail.com> In-Reply-To: <143C3C91-0198-4D62-8B81-9830CA7DB649@gmail.com> From: Bart Schaefer Date: Wed, 17 Apr 2024 15:13:31 -0700 Message-ID: Subject: Re: Inconsistent behavior of the test command with associative arrays To: limited time Cc: zsh-workers@zsh.org Content-Type: multipart/alternative; boundary="000000000000dee7c80616522ab4" X-Seq: 52890 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: --000000000000dee7c80616522ab4 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable This doesn't have anything to do with associative arrays and everything to do with "test" and quoting. On Wed, Apr 17, 2024 at 2:37=E2=80=AFPM limited time wrote: > % zsh -f > % typeset -A array=3D(key1 value1 key2 value2); > test $array[key1] ; echo $? ; > test $array[key2] ; echo $? ; > These two are "test somestring" which is defined as true. > test $array[key3] ; echo $? ; > test $array[key4] ; echo $? ; > These two are just "test" (with no arguments at all, because key3 and key4 have no value) which is defined as false. > if test $array[key1] -a $array[key2] ; then > echo "Condition evaluated to true" ; > fi > This is "test string -a string" which is true because neither string is empty. > if test $array[key3] -a $array[key4] ; then > echo "Condition evaluated to true" ; > fi > This is "test -a" because both expansions are empty and not quoted so they disappear from the command line entirely. By definition, "test -a" is treated as "test somestring" and is true. --000000000000dee7c80616522ab4 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
This doesn't have anything to do with associative= arrays and everything to do with "test" and quoting.

On Wed, Apr 17, 2024 at 2:37=E2= =80=AFPM limited time <burne= rmail4now@gmail.com> wrote:
% zsh -f
% typese= t -A array=3D(key1 value1 key2 value2);
test $array[key1] ; echo = $? ;
test $array[key2] ; echo $? ;
=

These two are "test somestring" which is defi= ned as true.
=C2=A0
test $array[key3] ; echo $? ;
test= $array[key4] ; echo $? ;

These two are just "test" (with no arguments at all, because key= 3 and key4 have no value) which is defined as false.
=C2=A0
if t= est $array[key1] -a $array[key2] ; then
=C2=A0 echo "Conditi= on evaluated to true" ;
fi =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0

This is "= test string -a string" which is true because neither string is empty.<= br>
=C2=A0
if test $array[key3] -a $array[key4] ; then =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0
=C2=A0 echo "Condition ev= aluated to true" ;
fi
This is "test -a" because both expansions are empty a= nd not quoted so they disappear from the command line entirely.
<= br>
By definition, "test -a" is treated as "test s= omestring" and is true.
--000000000000dee7c80616522ab4--