help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Hook for `set -v`


From: Greg Wooledge
Subject: Re: [Help-bash] Hook for `set -v`
Date: Wed, 10 Jun 2015 15:28:33 -0400
User-agent: Mutt/1.4.2.3i

> On Wed, Jun 10, 2015 at 12:21 PM, Peng Yu <address@hidden> wrote:
> > For example, I want to color the output.

"The output"?  Of set -v?  Or of the script?

I don't think set -v is really suited to what I am guessing you want
(though I might be guessing wrong, because as usual, you are not
forthcoming with details).

set -v writes out lines of the script *as bash reads them*.  Not as bash
executes them.  It's rarely of any real-world use to a script writer.
I guess it could be of use to someone hacking bash itself.

For example, given a script like this:

foo() {
  some stuff
}
for ((i=1; i<=10; i++)); do
  foo "$i"
done

Bash will read the entire function definition all at once, parse it, then
read the entire for loop all at once, and parse it.  Right after those
reads is when set -v triggers.  So you'll get two blobs of output from
set -v: one for the function definition, and one for the for loop
definition.  Then the loop will run, and set -v will do *nothing at all*,
because bash is no longer reading lines of script.

I don't really understand why you are interested in set -v, unless you
*thought* it did something different from what it actually does.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]