From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 8525 invoked from network); 20 Apr 2022 00:48:02 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 20 Apr 2022 00:48:02 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1650415682; b=j6HDHgn9j8UhBiO60NqpZvFUHn7d5OuHsA4E0sa/lJrHT5roKug8g/HyvJjEUgT7uFe9DRJvji rBXcLXGKW3YVPSNCoRd4xYQc9AW47Mps71p8OLhPsAL3fNwpQSlg8QTAfgSCyh/cBvFgzQWX0M MLtFVuAxEtrCgy7EHrBKBoFzzLlR8zqanjv5m44Ib1R+RQsp9gHvXLOwrZJD50+BH97g6vcHn2 4oNGiQAzPbmbXJIaE58WmqBH84fV5Xy87ToAzx51z8DcUOV21Gum9RS84nMgkyePZekNhNAnXj areld/E15Nu0OzCM9bFKyrBT3dxlvQi0Clsg9hvkle1Tww==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ej1-f43.google.com) smtp.remote-ip=209.85.218.43; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 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=1650415682; bh=pN8Dk41wUn62I3+EBgqA1jZb11aFV5kVdX5dYSjcD5Y=; 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=cIqfqvIZk2FMyXUlIqNl9EjeGZqbWtCeK428v6GYkNZzNiaMqM9eVBaURMBzMG/UB9jAQOVVIb xvt08+2kRuUfOPx0lXYuUCMgjJ8urcuUqp/5M1eGiyDHowmiUPytGn5C8weww/3D6xpeTD02/e hS0jK+QUAxWc28UyBTzsY+i8kEjzWLn8LGdCbkAXYnL2ZaREhiZckK7AzjVehxEspfSIrEZZqW LZVD2C98MpQDOvxMgUcUEFNS8yYPoN30w+KKkl+MgIlRQnBKKGdaqBYX1r/X5AujcWgTQ/M7Ws dS7W005c1ymTKzQ/5w+s82UcUAPXzz8X8akW1frb5o4j3g==; 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=gbiMnGNLYySAT0DtpXa+n9pTfvIDX+l7RSd5FWV4eVk=; b=sFUO3xADr633V0RMmCZ+RsQaSZ zDLtbAobIKShoPRNylBjQz2JmqlOYs4xd33aDhU1adh/h69Ry5/1Y7proVM5E/g5CffUrf41C1u9H 5CW6EVAiVcDjnn1DNW1yfULo9l8b0/H4Igf8B9DhMu3bjvX4gw/R5LerSmJU1XNaEb54auY2EaWdg bF0CINnzk9lvxvz4QYuW8OQCGEQfAx7uDGcO/FyjYYNk7pWmZh8jzbECuoQtAGkuS501ZUWAT2KaW 5eu9IjYUFeEJ/OALnhoNk7yPaMdsM3csH/zIYr57FqT25sqrz0An7IJSSgcNoWv0xE9ahXLPmxV8P Mx3zOaoA==; Received: from authenticated user by zero.zsh.org with local id 1ngyVl-000AFy-2M; Wed, 20 Apr 2022 00:48:01 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ej1-f43.google.com) smtp.remote-ip=209.85.218.43; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-ej1-f43.google.com ([209.85.218.43]:38502) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1ngyUj-0009YA-Hu; Wed, 20 Apr 2022 00:46:58 +0000 Received: by mail-ej1-f43.google.com with SMTP id r13so335335ejd.5 for ; Tue, 19 Apr 2022 17:46:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=gbiMnGNLYySAT0DtpXa+n9pTfvIDX+l7RSd5FWV4eVk=; b=kpyalwtUTQ9VfYai8wdQwGS3hu+EAvnLVaYt/S/qn59N1SamX4b8JruAZ56gHdUXgl y+1fg3m6D05KXyi3VUve4W5XQwurV+U+EhEyR41W0ZG/CjY81EocmTZTsYHvU8/BwSf1 y4ilBl3Zg3utjQA8N+I7dqmDBxogVOz4mQuQTu0E/0lXPZbKXK84qnhhlPVFclOzkXUv JQIfCqugYaOobKAzAAiYumDeWjUZ3rzuAKpBQT5034iT2TTFk7qbYGvLaIMkoY1D8dgz 7GPW9tRLCWdaQ08syY4AnM4m4ZoK+ANQxTp/U3DzRzvyODmzxoTGceT33hXfY8DbYsZi sXYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=gbiMnGNLYySAT0DtpXa+n9pTfvIDX+l7RSd5FWV4eVk=; b=igUJMB242XgVDTD3GrnxUEmtXEsTuuvFlX0030oEdfu8samLFe97X7RnXK+96fPp9v DLwHKMKgJ2HTP1wCZiTtt9LPgv13yanGZshkmrLY1rziyoeWuqeUlppPH69//JxH/Sqk VSasuZ5NCkzj4yMbpgN1vNiTOWJp3GpaFAHesOiI2dlh7fcmBD4QOo1uVXwvdN4tNRuc ZiOx08TW67nl/PwkxpwisTAsc3z70VX+UD/KNQ0Dsi8zzJqiZl3rExc7f++AhwnTXADZ eIj35w99HgrNrxGNFVAx6YBQ0pLHp6Dbydo9oKXC+NaDZqKOUL/7AWA1H0zYqbWzHJWJ +kXA== X-Gm-Message-State: AOAM5303P96K497xaFYwsVY7bWvl1qBX69pSI6AGMHz7LCD1BPEcXIc6 hBi1e8whf0OqitopJ/UVpv1hqWEsXavK43HJr3z3gw== X-Google-Smtp-Source: ABdhPJwFSRxvdR8xg/RNLzKK2wooqGKJ9ujeQlGR1y005iMEUdY4L7Z9glWT+iZN/zSP6OFxdDmcViTxGDj54BK/Xm0= X-Received: by 2002:a17:906:c1d7:b0:6e8:4f18:fede with SMTP id bw23-20020a170906c1d700b006e84f18fedemr16108515ejb.95.1650415616888; Tue, 19 Apr 2022 17:46:56 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Bart Schaefer Date: Tue, 19 Apr 2022 17:46:45 -0700 Message-ID: Subject: Re: Suggestion: Option to ignore unmatched quotes when (Q) parameter-expansion flag To: dg1727 Cc: "zsh-users@zsh.org" Content-Type: text/plain; charset="UTF-8" X-Seq: 27673 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: On Wed, Apr 13, 2022 at 7:01 PM dg1727 wrote: > > I prefer that the user be able to use not only backslash quoting, but also other forms of quoting (double quotes, single quotes, dollar single-quoting) to disable the pattern-matching meaning of characters the user may type, such as []. The problem, as Daniel already touched upon, is that you're trying to enable a limited form of input syntax rather than using pattern syntax. The parameter flags for handling patterns and quoting are not designed for that. Jumping ahead a bit ... > The zshexpn documentation for X says "Without the [X] flag, errors are silently ignored." It seems that, without (X), the unbalanced (") isn't 'ignored,' but rather causes the (Q) flag to fail entirely. It's the error that ignored, not the value that produced the error. That is, yes, the Q flag failed, because it could not remove quoting, but that didn't cause the surrounding command context to perceive/report an error state. A possible way to detect this is to use a test something like [[ "${var}" == "${(Q)var}" ]], which is true only if (Q) did nothing. > Even with shell option GLOB_SUBST enabled, the only quoting honoured when substituting the contents of a variable into a shell pattern is '\' backslash. Yes, because that's how patterns are defined. You're trying to translate between a different syntax and pattern syntax ... so what you first need is a parser for your other syntax. Unmatched quotes are probably the least of your problems. > u_input='*"[abc]"*' > a_string='one[abc]two' Let's think about what constitutes "a parser for your other syntax". The [[ ]] operator fits the bill, but it has to parse the contents of $u_input as the expression, rather than first parsing the expression and then expanding $u_input. Fortunately zsh has a trick up its sleeve: You can create and modify function definitions by assignment to fields in the $functions special parameter. Thus something like this: zmodload zsh/parameter functions[funkymatcher]='[[ $1 == '"${u_input}"' ]]' This will even throw parse errors on most "Bobby Tables" inputs, although if you want to prevent $(command) substitutions (and backticks) you'll need to figure that out yourself. Anyway, with that you can now call funkymatcher "${a_string}" and it will return 0 for a match and nonzero otherwise in exactly the way you want.