help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] How to pipe the output of 'set +v' to /dev/null?


From: Greg Wooledge
Subject: Re: [Help-bash] How to pipe the output of 'set +v' to /dev/null?
Date: Thu, 27 Jun 2013 08:19:25 -0400
User-agent: Mutt/1.4.2.3i

On Wed, Jun 26, 2013 at 06:02:41PM -0500, Peng Yu wrote:
> I'm not able to pipe the output of 'set +v' to /dev/null. Does anybody
> know how to do it?

set +v is the inverse of set -v.  That is, it is turning OFF a verbosity
option that you have previously enabled.

set -v works by telling Bash to write out each line of input as it is
read from the script, or the stdin file descriptor, from which Bash
receives its commands.  It writes these commands out *before* it
executes them.

Therefore, if you're doing a set +v after you have already done a set -v,
Bash is going to write out the "set +v" input line before executing it.

So, if you want to prevent Bash from writing out "set +v" when it reads
set +v from its input source, you need to perform some redirections
BEFORE the set +v command.  This will cause you not to see "set +v",
as that output will be redirected away from you.  However, you will see
the redirection command instead, because Bash will write THAT one to
stderr before executing it.

For example,

imadev:~$ cat foo
#!/bin/bash
set -v
echo "This is a command"
exec 3>&2 2>/dev/null
set +v
exec 2>&3-
echo "This is also a command"

imadev:~$ ./foo
echo "This is a command"
This is a command
exec 3>&2 2>/dev/null
This is also a command

So this begs the question, "What are you actually trying to do?"



reply via email to

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