zsh-users
 help / color / mirror / code / Atom feed
From: Dominik Vogt <dominik.vogt@gmx.de>
To: zsh-users@zsh.org
Subject: Re: uninvited members of associative array
Date: Fri, 16 Dec 2022 22:15:04 +0100	[thread overview]
Message-ID: <Y5zf2AKVWK04IxEh@localhost> (raw)
In-Reply-To: <eb26fde2-2c5c-bfb1-9012-c69b550cd78d@eastlink.ca>

On Fri, Dec 16, 2022 at 12:10:22PM -0800, Ray Andrews wrote:
> > I think you have a grave misconception of shells. Shells are
> > basically command line interpreters with some text processing.
> I know it.  All the extra functionality accreted over the years. It's an
> evolutionary cul-de-sac in that the latter additions are somewhat clumsy in
> as much as they have to contend with the earlier design.  Can't be helped.

> > There's no
> > conception of symbolic values; all input is just text.
> Except for those times when I wish it is was 'just text' but instead things
> are expanded.  Anyway how is a variable name not a symbol for the contents
> of the variable?

But variables are not even a real part of the shell, the shell
script or its data.  Every process has an associated environment
that consists of "key=value" pairs.  The parameter syntax in the
shell is just a way to manipulate the environment that is then
passed to the started processes.  The environment exists
independently of the shell.

> > Shells are
> > are not "programming languages".
> That's a strange thing to hear.  A program is a list of things on asks a
> computer to accomplish and zsh accomplishes them.  But you know more about
> all this than I do.

To begin with, the shell does not even have a fixed syntax that
could be written down in a rule book:  You can change the meaning
of the "program" from inside the program, for example by changing
options at run time or by overwriting the IFS variable, e.g.

  $ A="a,b-c"
  $ echo "$A"
  a,b-c

  # fiddle with IFS
  $ IFS=","
  echo "$A"
  a b-c

  # or even read value from user input
  $ read IFS
  -<return>
  $ echo "$A"
  a,b c

  # fiddling with options
  $ X=(a b c d e)
  $ setopt ksh_arrays; echo "${#X}"
  2
  $ unsetopt ksh_arrays; echo "${#X}"
  5

  # user input defines type of parameter
  $ unset A
  $ A[foo]=bar
  zsh: A: assignment to invalid subscript range
  $ read X
  -A<return>
  $ typeset "$X" A
  $ A[foo]="bar"
  $ echo "$(kv)A}"
  foo bar

  # redefine commands, aliases or even builtins
  $ read X
  ls<return>
  $ alias echo="$X"
  $ echo "Hello, world!"
  ls: cannot access 'Hello, world!': No such file or directory

I.e. the semantics of the script may depend on user input.

Then, the commands that the shell runs are mostly not defined by
the shell but externally.  You'd probably describe the script

  ls .
  rm -f foobarbaz

as "a program that lists non-hidden entries of the current
directory and then removes the entry foobarbaz if it exists and is
not a directory".  But that is not true.  What the script really
does is "execute a program 'ls' with argument '.', then execute a
program 'rm' with arguments '-f' 'foobarbaz'".  What the called
programs do is not part of the shell.  So, unless you want to
define the program as a sequence of "execute X with arguments Y1
... Yn" the shell really doesn't do anything close to what the
"program" is supposed to do.

--

Of course modern shells have lots of self contained builtin
commands and control structures that resemble programming
languages.

Ciao

Dominik ^_^  ^_^

--

Dominik Vogt


  reply	other threads:[~2022-12-16 21:16 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-15 23:48 Ray Andrews
2022-12-16  0:05 ` Lawrence Velázquez
2022-12-16  0:48   ` Ray Andrews
2022-12-16  1:29     ` Lawrence Velázquez
2022-12-16  2:09     ` Dominik Vogt
2022-12-16  2:56       ` Ray Andrews
2022-12-16  3:21         ` Lawrence Velázquez
2022-12-16  4:16           ` Ray Andrews
2022-12-16 10:05             ` Dominik Vogt
2022-12-16 14:13               ` Ray Andrews
2022-12-16 15:19                 ` Dominik Vogt
2022-12-16 19:14                   ` Ray Andrews
2022-12-16 16:30                 ` Daniel Shahaf
2022-12-16 18:21                   ` Ray Andrews
2022-12-16 19:04                     ` Dominik Vogt
2022-12-16 20:10                       ` Ray Andrews
2022-12-16 21:15                         ` Dominik Vogt [this message]
2022-12-16 21:33                           ` Bart Schaefer
2022-12-16 21:59                             ` Dominik Vogt
2022-12-16 22:15                               ` Bart Schaefer
2022-12-16 23:33                                 ` Ray Andrews
2022-12-17 12:47                                   ` Pier Paolo Grassi
2022-12-17 17:32                                     ` Ray Andrews
2022-12-17 18:10                                 ` Ray Andrews
2022-12-17 18:19                                   ` Roman Perepelitsa
2022-12-17 20:31                                     ` Ray Andrews
2022-12-17 20:49                                       ` Bart Schaefer
2022-12-17 21:07                                       ` Lawrence Velázquez
2022-12-17 21:52                                         ` Ray Andrews
2022-12-17 22:10                                           ` Bart Schaefer
2022-12-17 23:41                                             ` Daniel Shahaf
2022-12-18  0:15                                             ` Ray Andrews
2022-12-18  0:25                                               ` Daniel Shahaf
2022-12-18  2:13                                                 ` Ray Andrews
2022-12-18 20:12                                                   ` Daniel Shahaf
2022-12-18 20:26                                                     ` Bart Schaefer
2022-12-18 20:41                                                       ` Ray Andrews
2022-12-18  3:44                                               ` Lawrence Velázquez
2022-12-17 23:25                                         ` Daniel Shahaf
2022-12-16 21:33                           ` Ray Andrews
2022-12-16 20:25                       ` Daniel Shahaf
2022-12-16 21:43                         ` Dominik Vogt
2022-12-16  3:20 ` Bart Schaefer
2022-12-16  4:15   ` Ray Andrews
2022-12-16  8:12 ` Roman Perepelitsa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y5zf2AKVWK04IxEh@localhost \
    --to=dominik.vogt@gmx.de \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).