Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Order of variable substitution (any SUS guru out there?)



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



Messages sorted by: Reverse Date, Date, Thread, Author