Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Order of variable substitution (any SUS guru out there?)
- X-seq: zsh-workers 18911
- From: Dan Nelson <dnelson@xxxxxxxxxxxxxxx>
- To: Borzenkov Andrey <Andrey.Borzenkov@xxxxxxxxxxx>
- Subject: Re: Order of variable substitution (any SUS guru out there?)
- Date: Mon, 28 Jul 2003 02:11:30 -0500
- Cc: "'zsh-workers@xxxxxxxxxx'" <zsh-workers@xxxxxxxxxx>
- In-reply-to: <6134254DE87BD411908B00A0C99B044F06498092@xxxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <6134254DE87BD411908B00A0C99B044F06498092@xxxxxxxxxxxxxxxxxxxxxxx>
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@xxxxxxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author