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

  • Home
  • SEARCH
  • 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 4617302
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:06:19+00:00 2026-05-22T02:06:19+00:00

I have bash script where i have echo before every command showing what is

  • 0

I have bash script where i have echo before every command showing what is happening.

But i need to disbale echo when setting as cron job and then enable again if do some testing.

i find it very hard to go to each line and then add/remove comment

is there anything which i can include at top something like

enable echo or disable echo

so that i don’t have to waste time

  • 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-22T02:06:20+00:00Added an answer on May 22, 2026 at 2:06 am

    The absolute easiest would be to insert the following line after the hashbang line:

    echo() { :; }
    

    When you want to re-enable, either delete the line or comment it out:

    #echo() { :; }
    

    If you’re not using echo but printf, same strategy, i.e.:

    printf() { :; }
    

    If you absolutely need to actually echo/printf something, prepend the builtin statement, e.g.:

    builtin echo "This 'echo' will not be suppressed."
    

    This means that you can do a conditional output, e.g.:

    echo () {
      [[ "$SOME_KIND_OF_FLAG" ]] && builtin echo $@
    }
    

    Set the SOME_KIND_OF_FLAG variable to something non-null, and the overridden echo function will behave like normal echo.


    EDIT: another alternative would be to use echo for instrumenting (debugging), and printf for the outputs (e.g., for piping purposes). That way, no need for any FLAG. Just disable/enable the echo() { :; } line according to whether you want to instrument or not, respectively.


    Enable/Disable via CLI Parameter

    Put these lines right after the hashbang line:

    if [[ debug == "$1" ]]; then
      INSTRUMENTING=yes  # any non-null will do
      shift
    fi
    echo () {
      [[ "$INSTRUMENTING" ]] && builtin echo $@
    }
    

    Now, invoking the script like this: script.sh debug will turn on instrumenting. And because there’s the shift command, you can still feed parameters. E.g.:

    • Without instrumenting: script.sh param1 param2
    • With instrumenting: script.sh debug param1 param2

    The above can be simplified to:

    if [[ debug != "$1" ]]; then
      echo () { :; }
      shift
    fi
    

    if you need the instrumenting flag (e.g. to record the output of a command to a temp file only if debugging), use an else-block:

    if [[ debug != "$1" ]]; then
      echo () { :; }
      shift
    else
        INSTRUMENTING=yes
    fi
    

    REMEMBER: in non-debug mode, all echo commands are disabled; you have to either use builtin echo or printf. I recommend the latter.

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

Sidebar

Related Questions

I have a bash script I want to run every 5 minutes from cron...
Greetings all. I'm setting up a cron job to execute a bash script, and
I have a bash shell script that loops through all child directories (but not
I have a bash script that checks some log files created by a cron
I have a Bash script that builds a string to run as a command
I have a small bash script that greps/awk paragraph by using a keyword. But
I have a strange issue, relating to running a BASH script via cron (invoked
I have simple bash script find.sh for finding the files ==>cat find.sh echo $1
I have a bash script where I trap errors using the trap command, and
I have a bash script that creates a Subversion patch file for the current

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.