Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6909385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:40:58+00:00 2026-05-27T08:40:58+00:00

When I write bash scripts I usually get the verbose mode this way (simplified):

  • 0

When I write bash scripts I usually get the verbose mode this way (simplified):

_V=0

while getopts "v" OPTION
do
  case $OPTION in
    v) _V=1
       ;;
  esac
done

and then every time I want a “verbose output” I type this:

[ $_V -eq 1 ] && echo "verbose mode on" || echo "verbose mode off"

or for example this:

[ $_V -eq 1 ] && command -v || command

Is there a way to do it more elegant? I was thinking about defining a function named “verbose” and type it instead of [ $_V -eq 1 ], but this would only be a tiny improvement.

I’m sure, there is more common way to do it…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:40:58+00:00Added an answer on May 27, 2026 at 8:40 am

    As you noticed, you can define some log functions like log, log_debug, log_error, etc.

    function log () {
        if [[ $_V -eq 1 ]]; then
            echo "$@"
        fi
    }
    

    It can help increasing your main code readability and hide show\nonshow logic into logging function.

    log "some text"

    If _V(global variable) is equal 1 “some text” will be printed, in other case it will not.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it better practice to write Bash scripts or Bourne scripts? My team writes
Being a Linux administrator, I used to write my scripts in Bash, TCL and,
I have some bash scripts, some simple ones to copy, search, write lines to
I need to write a bash script , and would like it to parse
I have to write a bash script that makes lot of things. I'd like
I need to write a bash script to do something as another user and
I am attempting to write a bash script and I am having difficulty making
I'm trying to write a bash script that will process a list of files
I'm trying to write a bash script that wraps whatever the user wants to
I want to write a sh/bash script that can determine whether a particular directory

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.