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 autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 13797 invoked from network); 20 Nov 2022 20:17:58 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 20 Nov 2022 20:17:58 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1668975478; b=DACeN2zXUCIVotrjiGcKnpGO5VJPs687gFjmVGxfEJeGri3/kVGFAKWcP6lsgTdtKo5nlDRnSJ oHThXiIOIjsELRO/shyrV8nJkIkqHrsDHuFjx75n9x/yrrkjZxnRMxcoC3YtGk+Pmytunr9OB0 SUa5utw4dM9+EcQu6UVQcF4gPcKFYncDtABsRZ0p38sQwBqWrb6mfxzijd+J2OxWXV5kOFEWUp lVyzshSiFedkUMoC+fd/KPU3X2EOlrb2jJgTlzUk9cS59KEsPdJth++bNfP0vfXtewzc5Lg9Jl E2+9W9fXPJUdyMVFwqWMl0Zb3iyFUEipxychmzW55DLOFA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (relay9-d.mail.gandi.net) smtp.remote-ip=217.70.183.199; 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=1668975478; bh=wTB3Lmh1XbU3PbLXvr0BzYkm036jAXjaonqDKOfqJXE=; 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=TLY+bEQ8DKoAi31q1QOr+p8WCR6pjcrtNzf/Lx8f8GmQh+bP/RoakaYnWidRf1f9wAw7IxUNW/ B4s6f4Tp4vOZmRNZVA+ZlBNSwxhsTBPeTuUkjpI8mkLKc7Em3L8czZHKt5AYrS8IDrhrVW418Q SRJn2OABggL9+1wjrN8nHb0xzzNVOWBvi6F3vTvyHHYuRafLZ4W33ge91tUkUHOAmJ9BWVZ9Du Fa5xfjtIbz66ihCTnH3r+QsPg2PQEGghprdPsOA7mhm0LNrUK285DmbXUHhKwS70jMiysDrY/5 YE+rt7XzvV03P1pgE8BwHix2VdTBeyFil7bU3z4FrfC7sg==; 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=2dz46DGPsngnbty1rOqew6cUvBXNvyqwYpvP98nGoR0=; b=IUOc5fHvppWbsQBkoJUyKRJhha D2MMKphPN17lJ9WPUVUdOdwj2hvtG5RBJ7OEsWsvP5yF9cejOldWIILgHarKQMNWsyCUtnab9+Ku+ vxkCPRTCBRffbo2chCCMroEzg2xtegu+3om8hWIbXV641iWQZIpgWIvFmxojyRJYdUQoqy1eVwl1s qmicD9n/gTtnA09AXRw2Qh1J/TdRg9wEzvj/1h3zfDF0rn9z5zEoGCkSRo6g3P4iYW0/GudU7ErE2 zVGFgUnpq1Arr1117JpkzfyDyacoNwOuSDEuB/LIf8Pw2uoz17nQbpXh0scy+2FF1hj2DTKvY7fjI tjcVhDew==; Received: by zero.zsh.org with local id 1owqlI-0009J3-GL; Sun, 20 Nov 2022 20:17:56 +0000 Authentication-Results: zsh.org; iprev=pass (relay9-d.mail.gandi.net) smtp.remote-ip=217.70.183.199; dmarc=none header.from=chazelas.org; arc=none Received: from relay9-d.mail.gandi.net ([217.70.183.199]:58145) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1owqkP-0008cp-D4; Sun, 20 Nov 2022 20:17:02 +0000 Received: (Authenticated sender: stephane@chazelas.org) by mail.gandi.net (Postfix) with ESMTPSA id CAE76FF805; Sun, 20 Nov 2022 20:16:59 +0000 (UTC) Date: Sun, 20 Nov 2022 20:16:59 +0000 From: Stephane Chazelas To: Ray Andrews Cc: zsh-users@zsh.org Subject: Re: why is eval needed? Message-ID: <20221120201659.na4ypuivspeoowhu@chazelas.org> Mail-Followup-To: Ray Andrews , zsh-users@zsh.org References: <20221119164852.hwujmufa6hn5lotr@chazelas.org> <352823cc-954a-fa79-d830-d69d593b1c02@eastlink.ca> <3fa3f7ff-1733-4730-a62f-dd0e138c3b72@app.fastmail.com> <20221120085519.szudhyg5ewrw3b4o@chazelas.org> <20221120150848.74di3mpjwnfcul34@chazelas.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Seq: 28423 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-11-20 08:27:01 -0800, Ray Andrews: > > On 2022-11-20 07:08, Stephane Chazelas wrote: > > zsh doesn't impose anything. "-L 2" is a string made of 4 > > characters in any shell or programming language. There's no > > programming language where "-L 2" means 2 strings -L and 2. > > But that's the thing, I'd naively thought the variable could be inserted in > the command string and be 'just' a string of characters, but zsh imposes > that 'tree' must see '-L 2' as a single entity, yes? No, you have it completely backwards. And I think at the heart of your misunderstanding there is the misconception that you pass a "command string" to an executable. You do not, you pass a list of arguments. On Unix-like systems, execution of commands are with the execve() system call which takes 3 arguments: 1. the path name to the executable 2. a list of arguments: argv[] 3. a list of environment variables: envp[] What is commonly refered to as a command line is the shell's interface to that system call. VAR1=foo VAR2=bar cmd 'arg 1' arg2 Is how you tell your shell to do a execve("/path/to/cmd", ["cmd", "arg 1", "arg2"], [exportedvariable, "VAR1=foo", "VAR2=bar"]) You do not pass the "cmd 'arg 1' arg2" string as argument to /path/to/cmd. >  As shown, we need word > splitting to solve the problem and show tree what it wants to see. Or, as I > was speculating, some way of just flattening the string back to nothing more > than a string of characters -- but then again, probably tree wouldn't like > that either, perhaps the string is always 'packaged' into words?  If so, > then there's no avoiding that we must word-split '-L 2' into two words and > there's nothing to wish for. Why store those two arguments as a string with a space in between them and then ask the shell to split it, that makes no sense. Just store those two arguments and pass them to tree, that's exactly what arrays are for. In several shells like rc or fish, all variables are arrays (also in csh, but csh has many other issues of its own). >From a design point of view, that's the most sensible thing to do as what shells deal with primarily is the list of arguments to commands¹ zsh: args=(-L 1); tree $args rc: args=(-L 1); tree $args fish: set args -L 1; tree $args tcsh: set args = (-L 1); tree $args:q ksh: set -A args -- -L 1; tree "${args[@]}" ksh93/bash2+(/zsh): args=(-L 1); tree "${args[@]}" (¹ a complication and a spanner in the works is that environment variables (those VAR=value strings passed in envp[] above) are string/scalar only; in csh and in the Bourne shell, shell variables and env variables were more separated than they are in modern shells). If you wish arg='-L 2' tree $arg passed "-L" and "2" as separate arguments to tree, do you also wish that: file='my file.txt' rm -- $file Also passed "my" and "file.txt" as separate arguments to rm for rm to unlink those 2 files? What about: files=( 'my file.txt' 'my other file.txt' ) rm -- $files Should they be split too? How about: text='shutdown|reboot' echo $text Should that run echo shutdown|reboot and reboot? [...] > > Calls tree with "-L" and "1" as arguments is not that bash > > doesn't do some sort of magic "grouping" that zsh would be > > doing, but that ksh/bash contrary to zsh does that extra layer > > of $IFS-splitting from the Bourne shell on top of the syntax > > parsing as the default value of $IFS happens to contain the > > space character. > Ah!  So my little issue is a zsh exclusive? No, again, any recent shell (i.e. post 1980) that had no intention of being compatible with the Bourne shell including rc (and derivatives like akanga or es) and fish behave like zsh in this instance². In fish, set arg '-L 1' tree $arg Or in rc/es/akanga: arg = '-L 1' tree $arg all call tree with one "-L 1" argument. (² and even better, zsh still has that issue that unquoted expansions to empty removal, one of the issues with Bourne-like shells that it hasn't fixed. rc/es/akanga/fish have). >  Not complaining tho, I don't > like zsh doing things I didn't ask it to do so if in this case I need to > request a word split that's just fine.  After all it's tree that's being > difficult so the problem is rare and easily solved. No, it's not tree being difficult. In any command doing cmd '-o arg' is passing the " arg" string as argument to the -o option. sort '-o file' file Will sort the "file" file into the " file" file just like you asked. If you want to sort it into itself, it's sort -o file file [...] > > nm is a standard development command (though not -D which AFAIK > > is a GNU extension). Part of GNU binutils on GNU systems. > Ah, that's why I can't find it.  It's hard to find commands so packaged. apt-file is your friend. For the POSIX standard (2018 edition) see https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/ [...] > > Again, tree has nothing to do with the GNU project. > > I dunno, I get it all from Debian and Debian is a GNU/Linux OS so I don't > know more than that. On Debian dpkg -S =tree Will tell you what package the tree command comes from. apt showsrc that-package Will tell you how it was built and generally where the source came from. Here, not from gnu.org but from http://mama.indstate.edu/users/ice/tree/ http://mama.indstate.edu/users/ice/tree/changes.html shows it has a long history and might be even as old as zsh. -- Stephane