Sample Header Ad - 728x90

How to suppress output for set +v / set +o verbose (disabling verbose flag) in bash?

2 votes
1 answer
258 views
Script
#!/bin/bash
set -v
echo "verbose echo"
{ set +v; } &>/dev/null
echo "non verbose echo"
gives the following output:
echo "verbose echo"
verbose echo
{ set +v; } &>/dev/null
non verbose echo
I want to suppress output for { set +v; } &>/dev/null and get the following output:
echo "verbose echo"
verbose echo
non verbose echo
I tried the approach above which is described [here](https://stackoverflow.com/a/64644990/1455694) for suppressing output for disabling xtrace (x) flag with command { set +x; } &>/dev/null and it is working for this xtrace flag. Have not found related info in manuals for bash and set. As work around this can be achieved by means of subshell call like shown [here](https://stackoverflow.com/a/19392242/1455694) . But is this possible without using subshell?
Asked by Anton Samokat (289 rep)
Jul 26, 2024, 06:57 AM
Last activity: Jul 26, 2024, 08:17 AM