zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk (Zsh hackers list)
Subject: The sh substitution problem.
Date: Mon, 10 Jun 2002 13:05:14 +0100	[thread overview]
Message-ID: <24097.1023710714@csr.com> (raw)

namely ${1+"$@"} when using `sh' word-spliting makes a scalar out of "$@"
and splits it later on, with consequent undesirable effects.

I thought I had a way of doing the important cases (i.e. the ones
required for POSIX) simply but it turns out it doesn't work.  We just
have a completely different notion of how a command line word is formed
(because ours is more logical :-)).  So I've given that up.

I have a vague plan for doing it `properly' but it doesn't fill me with
delight:
 - When calling prefork() from multsub(), don't remove nulls (hence
   preserving information about quotes, which are retained as Snull,
   Dnull and Bnull).
 - In multsub(), handle arrays properly, i.e. stick the results in what 
   is currently its second argument.  This will have knock-on effects
   since paramsubst() messes around with val and aval all the time.  The
   way mult_isarr has been hacked in to avoid the calling sequence may
   make this more difficult.  (Ideally we would replace mult_isarr by
   making multsub() always return arrays.  This is probably even harder,
   but I don't understand the details of mult_isarr, which handles
   nested substitutions, well enough to say.)

   [It might be possible to keep val and aval as a pair in a structure,
   a sort of pseudo-parameter, and only convert between scalar and array
   when really necessary with a `forcescalar' or `forcearray'
   function/macro.]
 - Avoid joining words before splitting them (unless it is a forced
   join with a given string).  This changes the current rules but is
   inevitable for getting this to work at all.  This probably also means
   handling certain types of scalar result by joining arrays at this point
   instead of before (even if they are not going to be split).  This is
   also probably tricky because there are umpteen different ways of
   ending up with a scalar.  This is probably where we would have to do
   any joining due to letting multsub() always return an array.  I used
   the word `probably' three times in that paragraph.
 - When splitting, handle a loop over multiple array elements and
   keep track of quotes.  This also fixes:
     % ARGV0=sh zsh
     $ set word
     $ print -l ${1+'this should not be split'} 
     this
     should
     not
     be
     split

This is tricky and I have no idea of its detailed feasibility.  If
anyone wants to try they should.  Otherwise just make comments.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 392070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************


             reply	other threads:[~2002-06-10 12:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-10 12:05 Peter Stephenson [this message]
2002-06-10 16:07 ` Bart Schaefer

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=24097.1023710714@csr.com \
    --to=pws@csr.com \
    --cc=zsh-workers@sunsite.dk \
    /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).