zsh-users
 help / color / mirror / code / Atom feed
* Zsh Guide chapter 5 (substitutions)
@ 2001-08-15 23:00 Peter Stephenson
  2001-08-16  2:31 ` Bart Schaefer
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Peter Stephenson @ 2001-08-15 23:00 UTC (permalink / raw)
  To: Zsh users list

I've uploaded a new version of A User's Guide to the Z-Shell which you
can find at
  http://sunsite.dk/zsh/Guide/

The main addition is chapter 5, which talks about all forms of shell
substitutions and expansions.  Chapter 3 has been slightly edited.  I'd
be interested in any comments on either, of course.  It's possible
chapter 3 is a little indigestible and I could move some of the
marginalia to a later chapter or appendices or whatever.

There are now PDF versions.  These were created by pdflatex; I suspect
they are not as well compressed as you would get with Distiller, but
they are certainly smaller than the PostScript versions.

-- 
Peter Stephenson <pws@pwstephenson.fsnet.co.uk>
Work: pws@csr.com
Web: http://www.pwstephenson.fsnet.co.uk


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Zsh Guide chapter 5 (substitutions)
  2001-08-15 23:00 Zsh Guide chapter 5 (substitutions) Peter Stephenson
@ 2001-08-16  2:31 ` Bart Schaefer
  2001-08-17 16:55 ` Bart Schaefer
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 11+ messages in thread
From: Bart Schaefer @ 2001-08-16  2:31 UTC (permalink / raw)
  To: Peter Stephenson, zsh-users

On Aug 16, 12:00am, Peter Stephenson wrote:
} Subject: Zsh Guide chapter 5 (substitutions)
}
} The main addition is chapter 5, which talks about all forms of shell
} substitutions and expansions.  Chapter 3 has been slightly edited.  I'd
} be interested in any comments on either, of course.  It's possible
} chapter 3 is a little indigestible and I could move some of the
} marginalia to a later chapter or appendices or whatever.

Here's something I noticed in Chapter 3:

---------------
  ./myscript 2> >(grep -v idiot >error.log) |
       process-output >output.log


a little abstract, but here the main point of the script `myscript'
is to produce some output which undergoes further processing on the
right-hand side of the pipe. However, we want to process the error
output here, by filtering out occurrences of lines which use the word
`idiot', before dumping those errors into a file error.log. So we get an
effect similar to having two pipelines at once, one for output and one
for error. Note again the two `>' signs present next to one another to
get that effect. Don't remove the space between them, either: for what
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
that will do, and for more on the meaning of `2>', see the section on
redirections, below.
---------------

I don't know what you're driving at, there.  2>>(thing) and 2> >(thing)
are exactly equivalent.  However, 2>(thing) is the same as 2 >(thing),
and not the same as 2> (thing), which is a syntax error that I've never
seen before in ten years of using zsh ("missing end of name").

I may have some remarks about chapter 5 when I get there ...

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Zsh Guide chapter 5 (substitutions)
  2001-08-15 23:00 Zsh Guide chapter 5 (substitutions) Peter Stephenson
  2001-08-16  2:31 ` Bart Schaefer
@ 2001-08-17 16:55 ` Bart Schaefer
  2001-08-20 18:26 ` Bart Schaefer
  2001-08-21 14:21 ` Richard Curnow
  3 siblings, 0 replies; 11+ messages in thread
From: Bart Schaefer @ 2001-08-17 16:55 UTC (permalink / raw)
  To: Peter Stephenson, zsh-users

On Aug 16, 12:00am, Peter Stephenson wrote:
}
} The main addition is chapter 5, which talks about all forms of shell
} substitutions and expansions.

Asoorted comments:

 The only thing you can't quote with single quotes is another single
 quote. However, there's an option RC_QUOTES, in which RC presumably
 stands for recursive,

Nope, RC stands for RC.  The Plan 9 shell (I think it is) is named "rc",
and nearly everything in zsh that has "rc" at the beginning of the name
(as opposed to at the end) means that the feature was copied from the
Plan 9 shell.  (At the end, as in ".zshrc", "runtime configuration" is
the meaning usually reported in Unix lore.)

   % args "${(f)$(<file)}"
   2

 I don't remember what the `f' stands for, but we were already using up
 flag codes quite fast when it came along.

I think it's for "fold", although it was added at a time when I was
paying less attention to zsh development.  At least that's a plausible
mnemonic.

 All the assignment types are affected by the globbing flags `A' and
 `AA' which tell the shell to perform array and associative array
 assignment ...

Should not say "globbing flags".

 Note you need the colon, else you are asking the shell to test whether
 a parameter is set, and it becomes rather unset when it realises there
 isn't one to test.                        ^^^^^

I should think.

 4. Now we have `${array[(r)???????]}'. It may not be obvious
    (congratulations if the rest is), but the question marks are still
    active as a pattern: the fill-in operation that put them there
    didn't turn them into strings, because that only happens at the
    point where a parameter is substituted, whereas these were added
    later. The subscript flag `(r)' means `reverse match',  ...

You're both right and wrong there.  It actually doesn't matter whether
the question marks are still active as a pattern or not.  Just go round
mumbling `extra layer of pattern expansion' and everyone will think you
know what you're talking about.

I have to stop now and go do this annoying "work" thing.  Back to part
5.6 later.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Zsh Guide chapter 5 (substitutions)
  2001-08-15 23:00 Zsh Guide chapter 5 (substitutions) Peter Stephenson
  2001-08-16  2:31 ` Bart Schaefer
  2001-08-17 16:55 ` Bart Schaefer
@ 2001-08-20 18:26 ` Bart Schaefer
  2001-08-20 18:35   ` Phil Pennock
  2001-08-21 16:38   ` Bart Schaefer
  2001-08-21 14:21 ` Richard Curnow
  3 siblings, 2 replies; 11+ messages in thread
From: Bart Schaefer @ 2001-08-20 18:26 UTC (permalink / raw)
  To: Peter Stephenson, zsh-users

In this example:

   % fn() { print "Twice ${1:-0} is $(( 2 * ${1:-0} ))"; }
   % fn
   Twice 0 is 0

It'd be even more exemplary to write:

     fn() { print "Twice ${1:=0} is $(( 2 * $1 ))"; }

Moving on:

 the `^' character turns on the option just for that expansion, as `='
 does with SH_WORD_SPLIT (can't think of a good mnemonic, sorry).

Think of proofreaders' marks, where a carat means to insert a new word in
between two other words.

 In addition to `*' and `?', which are so basic that even DOS had them
 (though I never quite worked out exactly what it was doing with them a
 lot of the time)

I'm going to guess that you really don't want to know.

 ... anywhere where history substitution doesn't get it's hands
 on the `!' first.                                   ^^^^

Apostrophe abuse!

 Note one point mentioned in the FAQ --- probably indicating the reason
 that `^' is only available with EXTENDED_GLOB switched on.  Some
 commands use an initial `^' to indicate a control character

In fact, there's another reason:  Some keyboards used not to have a `|'
character, so many older versions of the Bourne shell interpret `^' as
`|', that is, `echo foo^grep f' would run grep and output `foo'.

 Slightly less obviously, the `**/*' matches files in the current
 directory, while the `*/CVS' never matches a `CVS' in the current
 directory, so that could appear. If you want to, you can fix that up
 like this:

    print **/*~(*/|)CVS(/*|)(/)

Easier is

    print ./**/*~*/CVS(/)

but I suppose that doesn't show that slashes can appear in parens on
the right side of the tilde.

 A `~' at the beginning is never treated as excluding what follows; as
 you already know, it has other uses.

Might be worth pointing out here or elsewhere that (#i)~/foo does NOT
mean ~(#i)/foo, but rather means (#i)(|)~/foo, that is, the presence of
(#i) means that `~' is no longer at the start of the pattern.  Or maybe
that's a bug?

In the table of ksh glob equivalences quoted from the FAQ, you've included
the footnote reference [1] but not the footnote itself.

 ... since no-one would right two *'s in a row for any other reason.

They might, however, write two wrongs.

There are a couple of minor typos in the first few paragraphs about glob
qualifiers: "usual" for "usually" and "t((%b))" for "((%b))".  Also,
"whackier" -- on this side of the pond we spell it without the "h", but
maybe this is a "colour programme" sort of thing.

Gotta stop now, back later for sections 5.9.7 and later.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Zsh Guide chapter 5 (substitutions)
  2001-08-20 18:26 ` Bart Schaefer
@ 2001-08-20 18:35   ` Phil Pennock
  2001-08-21 16:38   ` Bart Schaefer
  1 sibling, 0 replies; 11+ messages in thread
From: Phil Pennock @ 2001-08-20 18:35 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 741 bytes --]

On 2001-08-20 at 18:26 +0000, Bart Schaefer wrote:
> There are a couple of minor typos in the first few paragraphs about glob
> qualifiers: "usual" for "usually" and "t((%b))" for "((%b))".  Also,
> "whackier" -- on this side of the pond we spell it without the "h", but
> maybe this is a "colour programme" sort of thing.

I've never seen it as "whacky" and I'm from the side which doesn't even
pretend to have a democracy.

However:
 <http://www.dictionary.com/cgi-bin/dict.pl?db=*&term=whacky>
lists it as an alternate spelling, and notes that the word is probably
derived from "out of whack".
-- 
It was only after their numbers had been reduced from 50 to 8 that
the other 7 dwarves began to suspect Hungry.  - Far Side

[-- Attachment #2: Type: application/pgp-signature, Size: 187 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Zsh Guide chapter 5 (substitutions)
  2001-08-15 23:00 Zsh Guide chapter 5 (substitutions) Peter Stephenson
                   ` (2 preceding siblings ...)
  2001-08-20 18:26 ` Bart Schaefer
@ 2001-08-21 14:21 ` Richard Curnow
  2001-08-21 15:34   ` Bart Schaefer
  3 siblings, 1 reply; 11+ messages in thread
From: Richard Curnow @ 2001-08-21 14:21 UTC (permalink / raw)
  To: zsh-users

On page 74, 2nd para from the end,

  It seems a bit odd to signal a process to restart; why can't the operating
  system just restart it when you ask? The real answer is probably that signals
  provide an easy way for you to talk to the operating system without
  grovelling around in the dirt too much.

I think it's to provide a way for a process to save and restore state across
the suspension, by installing handlers for SIGTSTP and SIGCONT.  I can think of
a few cases I've come across where this applies :

- if the process has done anything horrible to its /dev/tty, (e.g. echo off,
  changed the per-line/per-char input (ICANON?) mode, made stdin use
  asynchronous I/O etc), which would leave an unusable environment for the user
  back at the shell prompt.

- some tools (verilog simulators etc) that use floating licenses seem to
  relinquish licenses when suspended and re-acquire them when restarted.  Very
  nice of them!

On Thu, Aug 16, 2001 at 12:00:18AM +0100, pws@pwstephenson.fsnet.co.uk wrote:
> I've uploaded a new version of A User's Guide to the Z-Shell which you
> can find at
>   http://sunsite.dk/zsh/Guide/
> 
> The main addition is chapter 5, which talks about all forms of shell
> substitutions and expansions.  Chapter 3 has been slightly edited.  I'd
> be interested in any comments on either, of course.  It's possible

-- 
Richard Curnow---by day : SuperH Core Architecture at STMicroelectronics
curnowr@bristol.st.com---------www.superh.com-------------www.st.com----
and by night >>---richard.curnow@go.to---http://go.to/richard.curnow/---


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Zsh Guide chapter 5 (substitutions)
  2001-08-21 14:21 ` Richard Curnow
@ 2001-08-21 15:34   ` Bart Schaefer
  0 siblings, 0 replies; 11+ messages in thread
From: Bart Schaefer @ 2001-08-21 15:34 UTC (permalink / raw)
  To: Richard Curnow, zsh-users

On Aug 21,  3:21pm, Richard Curnow wrote:
}
} On page 74, 2nd para from the end,
} 
}   It seems a bit odd to signal a process to restart; why can't the
}   operating system just restart it when you ask? The real answer is
}   probably that signals provide an easy way for you to talk to the
}   operating system without grovelling around in the dirt too much.
} 
} I think it's to provide a way for a process to save and restore state
} across the suspension, by installing handlers for SIGTSTP and SIGCONT.

Saving and restoring state is one reason that there are four signals to
stop a process (STOP, TSTP, TTIN, TTOU).  However, it's not the reason
that a signal is used for SIGCONT; Peter's more on target with that one.

There's no such thing as a SIGCONT handler, by the way.  The process
just picks up where it left off (possibly with system calls interrupted
depending on the operating system).  A typical TSTP handler looks like

    save_state();
    kill(getpid(), SIGSTOP);	/* STOP is not catchable */
    restore_state();

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Zsh Guide chapter 5 (substitutions)
  2001-08-20 18:26 ` Bart Schaefer
  2001-08-20 18:35   ` Phil Pennock
@ 2001-08-21 16:38   ` Bart Schaefer
  1 sibling, 0 replies; 11+ messages in thread
From: Bart Schaefer @ 2001-08-21 16:38 UTC (permalink / raw)
  To: Peter Stephenson, zsh-users

On Aug 20, I wrote:
}
} Might be worth pointing out here or elsewhere that (#i)~/foo does NOT
} mean ~(#i)/foo, but rather means (#i)(|)~/foo
} 
} Gotta stop now, back later for sections 5.9.7 and later.

And lo, in 5.9.7 PWS says:

   print (#i)~/.Z*

 doesn't work.

That doesn't say what it does do, though.

A little bit above that:

 You can put the flags at any point in the pattern, and they last either
 till the end, so in

The "either" lacks an "or."

Then I've got nothing until way down under zmv, where:

     [[ $f1 = (#b)${~pattern} ]] || next

That "next" should be a "continue".  (I myself am on the verge of
`alias next=continue' because I've been writing so much Perl at work
lately.)

And that's all, except that I'm left puzzling over this:

 The other tricky point is the use of double quotes in the eval. That
 means that if the second argument has a double quote in it, the shell
 will get very confused.

This refers to:

     eval "f2=\"$result\""

I'm left wondering whether

     f2=${(e)result}

wouldn't be equivalent and avoid the need for the double quotes?

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 11+ messages in thread

* RE: Zsh Guide chapter 5 (substitutions)
  2001-08-23  7:30 ` Borsenkow Andrej
@ 2001-08-23  7:41   ` Borsenkow Andrej
  0 siblings, 0 replies; 11+ messages in thread
From: Borsenkow Andrej @ 2001-08-23  7:41 UTC (permalink / raw)
  To: Borsenkow Andrej, martin.ebourne, zsh-users

> >   %hash2 = %hash;               typeset -A hash2;
hash2=(${(kv)hash})
> >
> > Surely this should be hash2=("${(@kv)hash}") in case of empty string
> > values.
> >
> 
> 
> No (at least, if running as zsh):
> 

Sorry, you are right. 


^ permalink raw reply	[flat|nested] 11+ messages in thread

* RE: Zsh Guide chapter 5 (substitutions)
  2001-08-22 17:10 martin.ebourne
@ 2001-08-23  7:30 ` Borsenkow Andrej
  2001-08-23  7:41   ` Borsenkow Andrej
  0 siblings, 1 reply; 11+ messages in thread
From: Borsenkow Andrej @ 2001-08-23  7:30 UTC (permalink / raw)
  To: martin.ebourne, zsh-users

> 
> I don't know if anyone has already pointed this out, but in the user
guide
> section 5.4.2:
> 
>   perl                          zsh
>   -----------------------------------------------------------------
>   %hash2 = %hash;               typeset -A hash2; hash2=(${(kv)hash})
> 
> Surely this should be hash2=("${(@kv)hash}") in case of empty string
> values.
> 


No (at least, if running as zsh):

bor@itsrm2% foo=(a "a a" b "b b")
bor@itsrm2% print -l $foo
a a
b b
bor@itsrm2% typeset -A bar
bor@itsrm2% bar=(${(kv)foo})
bor@itsrm2% print -l $bar   
a a
b b

-andrej


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Zsh Guide chapter 5 (substitutions)
@ 2001-08-22 17:10 martin.ebourne
  2001-08-23  7:30 ` Borsenkow Andrej
  0 siblings, 1 reply; 11+ messages in thread
From: martin.ebourne @ 2001-08-22 17:10 UTC (permalink / raw)
  To: zsh-users


I don't know if anyone has already pointed this out, but in the user guide
section 5.4.2:

  perl                          zsh
  -----------------------------------------------------------------
  %hash2 = %hash;               typeset -A hash2; hash2=(${(kv)hash})

Surely this should be hash2=("${(@kv)hash}") in case of empty string
values.

Also, a little above in 5.4.1, this bit is not quite right (missing the
'array[]').

 % array=(some words)
  % args() { print $#; }
  % args ${(r)s*}
  1
  % args ${(r)X*}
  0
  % args "${(r)X*}"
  1

Cheers,

Martin.




This e-mail message is CONFIDENTIAL and may contain legally privileged
information.  If you are not the intended recipient you should not  read,
copy, distribute, disclose or otherwise use the information in this e-mail.
Please also telephone or fax us immediately and delete the message from
your system.  E-mail may be susceptible to data corruption, interception
and unauthorised amendment, and we do not accept liability for any such
corruption, interception or amendment or the consequences thereof.


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2001-08-23  7:41 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-15 23:00 Zsh Guide chapter 5 (substitutions) Peter Stephenson
2001-08-16  2:31 ` Bart Schaefer
2001-08-17 16:55 ` Bart Schaefer
2001-08-20 18:26 ` Bart Schaefer
2001-08-20 18:35   ` Phil Pennock
2001-08-21 16:38   ` Bart Schaefer
2001-08-21 14:21 ` Richard Curnow
2001-08-21 15:34   ` Bart Schaefer
2001-08-22 17:10 martin.ebourne
2001-08-23  7:30 ` Borsenkow Andrej
2001-08-23  7:41   ` Borsenkow Andrej

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).