Date:        Sat, 1 Apr 2023 19:44:10 -0400
    From:        Saint Michael <vene...@gmail.com>
    Message-ID:  
<cac9csoaa0g97fzulurxmee6emrdum7zpzk+u20ymvwbjymv...@mail.gmail.com>

  | The compelling reason is: I may not know how many values are stored in the
  | comma-separated list.

Others have told you you're wrong, but this is not any kind of compelling
reason - you simply give one more variable name than you expected to need
(than you would have used otherwise) and then all the extra fields that
you wanted the shell to ignore will be assigned to it - which you are free
to ignore if you like, or you can test to see if anything is there, and
issue an error message (or something) if more fields were given than you
were expecting.   Much better behaviour than the shell simply ignoring
data (silently).

  | GNU AWK, for instance, acts responsibly in the same exact situation:
  | line="a,b,c,d";awk -F, '{print $1}' <<< $line
  | a

awk is a different language with different rules, used in a different way.
Further, it isn't all that different really - you're only using $1, but
awk doesn't simply discard the other fields, they're there, called $2 $3 ...
There's even NF which tells you how many are there.

kre


Reply via email to