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,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 16061 invoked from network); 28 Sep 2022 18:50:57 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 28 Sep 2022 18:50:57 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1664391057; b=sZ13ceNCGbJRMBrAUH9vS2BKk1BKWG2ve88JF3B7EKkKJj3xAs/hl901hf4S22wnkhuWKb8P62 7c/rqYnN2azCM1Nl0FXD8Fkkw0hqd/W8Bh2p0S+v8g90AppUxjuD0fyuP9oJpm+okXG83S0zFx e7lXE3Jyh1z4g4pDrCO9/YEZIvVjxMeQnG8g+p2zZQX6XMr2wDzC3trVTJQO7BoPbSDGJa6xJ0 NhZwlAZldBNkqRD/PMq4xBs3xy5TQV853Wur6S5jJGsxa+uVuMy7Ld/2wsNowMVOypu0YEMu4I SARKKkV2x8oEZW3vSTn0FZce/nZPAQTNbFBZbksXbHWFAA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (relay1-d.mail.gandi.net) smtp.remote-ip=217.70.183.193; dmarc=none header.from=chazelas.org; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1664391057; bh=uEDca31MHukJ+OZrq+HN8vfUFp7nAUtbsnXPQ45PqgA=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:DKIM-Signature; b=nrRwkD00DubkofBLgTCiC5qDDzk7RVe+fV6PtCLgVqVjaf2DR20hfIaGYFNVvb/EScnmeVRpYk uL7QxIrtWFgoxWcTXL48NT575U2cOae2qgt3UhhgEaRxtzp13ztaDKUwGz5RbT+1QcpFsSu1Do OeDzC5NmXapc5sUtZvihigeetnpFf5YH38ENRNfi6Q0OBxRZCDaONx7YfBq/L+SvyWR5mte5b3 RwaBrpSUyF0sb9QEuHWwtgLmxoG9eafL5QiFRjzmkZiXVOsouwp0pSSdcw/NdXfMzPW1WCpsk2 GATRs4SD68y9nCys4g+C2YGvvG+DZMKkilJCO9wChcWk6g==; 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:In-Reply-To:Content-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID; bh=r/qaEEKxljULfea8YpXyYSfzCay8FrPGKjnBzj1hhqU=; b=XgP7j8C0+pjVRU9AFd88rXi+Ji bxSMR4wo49b14CYfqYcNfmmTyCYluK1QDo1LQEw2CMHfyKwmNF+Je3elOt2BsRWcMqKBfEL6ApdGG hCuBXjNZuZjUJzfMkD5TPCmi+ju0DohVUCGcL4TcwX5ia0Xlza0bSpvh8ZDciLDlsDcIRFkARZiDB 9BVhxRzx2sLethLifzDLvcxZSbdLraYKSTi+W8uSnDi8pjGrEJ3G4lzkAfI5MlNiZaCMAv377RrO/ 7kdKwJCab02pyP2pyQKOlr/nPKBGBHj+/eQpM8EndvexnpAtBBOmUUWFv/0Q2RqC3dSgOowiu9Fge f2nocNoQ==; Received: from authenticated user by zero.zsh.org with local id 1odc92-00034d-Ku; Wed, 28 Sep 2022 18:50:56 +0000 Authentication-Results: zsh.org; iprev=pass (relay1-d.mail.gandi.net) smtp.remote-ip=217.70.183.193; dmarc=none header.from=chazelas.org; arc=none Received: from relay1-d.mail.gandi.net ([217.70.183.193]:32979) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1odc7q-0002Og-1K; Wed, 28 Sep 2022 18:49:43 +0000 Received: (Authenticated sender: stephane@chazelas.org) by mail.gandi.net (Postfix) with ESMTPSA id 97F4B240008; Wed, 28 Sep 2022 18:49:40 +0000 (UTC) Date: Wed, 28 Sep 2022 19:49:39 +0100 From: Stephane Chazelas To: Ray Andrews Cc: zsh-users@zsh.org Subject: Re: preserving single quotes Message-ID: <20220928184939.46gftnscdz22e5m3@chazelas.org> Mail-Followup-To: Ray Andrews , zsh-users@zsh.org References: <20220928100020.tn3debb7jkytyluz@chazelas.org> <0ede34f7-4684-8b48-700e-9555cccfa693@eastlink.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <0ede34f7-4684-8b48-700e-9555cccfa693@eastlink.ca> X-Seq: 28160 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: 2022-09-28 07:32:41 -0700, Ray Andrews: [...] > > dd="aptitude search '?name(libreoffice-java-common)'" > > ee=$(eval -- $dd) > My old friend eval.  But Bart advises to get away from it.  Anyway it works > for now. > > > Or: > > > > dd=( aptitude search '?name(libreoffice-java-common)' ) > > # or > ... > > ee=$( "$dd[@]" ) > Works.  But that puzzles me, it seems simplest, but how is that that saving > the aptitude string as an array preserves the single quotes? It seems > unintuitive that the method of saving the string would make the difference. [...] There seems to be some confusion as to the role of quotes there. Here you *do* want to remove the quotes, not preserve them. aptitude search '?name(libreoffice-java-common)' is code in the zsh language (or in that case most shell languages). That tells the shell: find a command called "aptitude" in the directories in $PATH and run it in a child process with 3 arguments: - aptitude - search - ?name(libreoffice-java-common) To do the same thing in another language, like perl, you'd do: system("aptitude", "search", "?name(libreoffice-java-common)"); In either case, the quotes (and "system", "(", "," or spaces) are not or the arguments passed to the command, they're just part of the language (zsh / perl). dd="aptitude search '?name(libreoffice-java-common)'" is also code in the zsh language that says store in the $dd variable: aptitude search '?name(libreoffice-java-common)' (including the spaces and single quotes, not double quotes which again are part of the zsh syntax to remove the special meaning of the space, ', ?, (, ) characters). $=dd is again code in the zsh language that says: - take the value of $dd - split it on $IFS characters to get a number of words - derive the command to run from the first word and pass all the words to it as arguments. So assuming the default value of $IFS, that will call /usr/bin/aptitude with these 3 arguments: - aptitude - search - '?name(libreoffice-java-common)' (including the 's!) aptitude search terms do understand single quotes as quoting operators, so instead of searching for packages whose name contains libreoffice-java-common, you're search for packages whose name (since name search is the default) contains ?name(libreoffice-java-common), same as if you had run: "aptitude" "search" "?name('~name(libreoffice-java-common)')" dd=(aptitude search '?name(libreoffice-java-common)') is shell code that says store in the dd array 3 elements: - aptitude - search - ?name(libreoffice-java-common) "${dd[@]}" Is shell code that says: expand to all the elements of the $dd array as separate words that will make up the list of arguments to the command (identified by the first element). -- Stephane