Search code examples
bashverbosity

Check current bash verbosity


I know bash can be set to verbose mode by using set -v, however I want to write a function that doesn't run in verbose mode even if called from a verbosed script.

While I'm aware I could disable verbosity by using set +v at the start of the function and end it with set -v, that would mean my function will set any script that calls it to verbose, even if it wasn't verbose before calling it.

Ideally I'd check the verbosity level at the start of the function, disable verbosity, and revert the verbosity change at the end of the function.

Is there a way to find current verbosity level?


Solution

  • if [[ $- =~ v ]]; then 
      echo "verbose enabled"
    else
      echo "verbose disabled"
    fi
    

    $-: Contains the current set of enabled options. See: help set