On Wed, Apr 04, 2018 at 11:25:26AM +0800, 積丹尼 Dan Jacobson wrote:
> $PS4 is for sh -x. Well, $PS5 or $PSv should be for sh -v!
>
> Imagine, with just a simple PS5='$ ', one could produce
> perfect dialogues,
>
> $ set -eu /tmp/x
> $ mkdir $@
> $ cd $@
> $ seq 3|xargs touch
> $ ls -U $@
> 3 2 1
Until you use a compound command like "if" or "for" or "while", or a
function. Then you suddenly realize how utterly useless sh -v actually
is, and why nobody ever bothers with it.
sh -v echoes lines as they ae *read* by the shell, not as they are
executed. In the case of a compound command, the entire command has
to be read before execution can begin.
If the script consists almost entirely of a while loop (pretty common),
then the entire while loop (i.e. the vast majority of the script)
has to be read, and thus echoed by -v, before anything in the loop
actually happens.