zsh-workers
 help / color / mirror / code / Atom feed
* Order of variable substitution (any SUS guru out there?)
@ 2003-07-28  6:38 Borzenkov Andrey
  2003-07-28  7:11 ` Dan Nelson
  0 siblings, 1 reply; 2+ messages in thread
From: Borzenkov Andrey @ 2003-07-28  6:38 UTC (permalink / raw)
  To: 'zsh-workers@sunsite.dk'

Several times I happily removed files by doing

find . -name ... | (cd /master/rep; cpio -pmv $PWD)

the problem is apparently $PWD is evaluated only after  cwd is changed so
cpio tries to copy files over themselves and removes them.

Reading SUS gives impression it is wrong. All substitutions are done
(conceptually) in one pass before any command executes. Shell here also
behaves the same:

$ find . -type f | (cd ../foo-m; cpio -pmv $PWD)
/home/bor/tmp/foo/id_dsa
/home/bor/tmp/foo/id_dsa.pub
/home/bor/tmp/foo/id_rsa
/home/bor/tmp/foo/id_rsa.pub
11 blocks

while zsh gives

bor@itsrm2% find . -type f | (cd ../foo-m; cpio -pmv $PWD)
cpio: Attempt to pass a file to itself.
cpio: Attempt to pass a file to itself.
cpio: Attempt to pass a file to itself.
cpio: Attempt to pass a file to itself.
0 blocks
4 error(s)

in this case I have sensible cpio that does not destroy target like GNU cpio
does but well ...

-andrey


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

* Re: Order of variable substitution (any SUS guru out there?)
  2003-07-28  6:38 Order of variable substitution (any SUS guru out there?) Borzenkov Andrey
@ 2003-07-28  7:11 ` Dan Nelson
  0 siblings, 0 replies; 2+ messages in thread
From: Dan Nelson @ 2003-07-28  7:11 UTC (permalink / raw)
  To: Borzenkov Andrey; +Cc: 'zsh-workers@sunsite.dk'

In the last episode (Jul 28), Borzenkov Andrey said:
> Several times I happily removed files by doing
> 
> find . -name ... | (cd /master/rep; cpio -pmv $PWD)
> 
> the problem is apparently $PWD is evaluated only after  cwd is
> changed so cpio tries to copy files over themselves and removes them.
> 
> Reading SUS gives impression it is wrong. All substitutions are done
> (conceptually) in one pass before any command executes.

Are you referring to 
http://www.opengroup.org/onlinepubs/007904975/utilities/xcu_chap02.html#tag_02_09_01
?  That section talks about "simple commands".  You've got a pipeline
and a compound command, composed of three simple commands, each of
which gets its variables expanded at different times.

Under your interpretation, "(a=1 ; echo $a)" would not work, since "$a"
would be evaluated beofre "a=1" was executed.  :)

> Shell here also behaves the same:
> 
> $ find . -type f | (cd ../foo-m; cpio -pmv $PWD)
> /home/bor/tmp/foo/id_dsa
> /home/bor/tmp/foo/id_dsa.pub
> /home/bor/tmp/foo/id_rsa
> /home/bor/tmp/foo/id_rsa.pub
> 11 blocks

"Shell" being what?  
 
> while zsh gives
> 
> bor@itsrm2% find . -type f | (cd ../foo-m; cpio -pmv $PWD)
> cpio: Attempt to pass a file to itself.
> cpio: Attempt to pass a file to itself.
> cpio: Attempt to pass a file to itself.
> cpio: Attempt to pass a file to itself.
> 0 blocks
> 4 error(s)

Ash and bash do the same as zsh.  Try storing your original PWD in
another variable first:

pwd=$PWD ; find . -type f | (cd ../foo-m; cpio -pmv $pwd)
 
-- 
	Dan Nelson
	dnelson@allantgroup.com


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

end of thread, other threads:[~2003-07-28  7:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-28  6:38 Order of variable substitution (any SUS guru out there?) Borzenkov Andrey
2003-07-28  7:11 ` Dan Nelson

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