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 6386901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:05:07+00:00 2026-05-25T03:05:07+00:00

I’m looking for a way to create a switch for this bash script so

  • 0

I’m looking for a way to create a switch for this bash script so that I have the option of either printing (echo) it to stdout or executing the command for debugging purposes. As you can see below, I am just doing this manually by commenting out one statement over the other to achieve this.

Code:

#!/usr/local/bin/bash

if [ $# != 2 ]; then
    echo "Usage: testcurl.sh <localfile> <projectname>" >&2
    echo "sample:testcurl.sh /share1/data/20110818.dat projectZ" >&2
    exit 1
fi

echo /usr/bin/curl -c $PROXY --certkey $CERT --header "Test:'${AUTH}'" -T $localfile $fsProxyURL
    #/usr/bin/curl -c $PROXY --certkey $CERT --header "Test:'${AUTH}'" -T $localfile $fsProxyURL

I’m simply looking for an elegant/better way to create like a switch from the command line. Print or execute.

  • 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-25T03:05:07+00:00Added an answer on May 25, 2026 at 3:05 am

    One possible trick, though it will only work for simple commands (e.g., no pipes or redirection (a)) is to use a prefix variable like:

    pax> cat qq.sh
    ${PAXPREFIX} ls /tmp
    ${PAXPREFIX} printf "%05d\n" 72
    ${PAXPREFIX} echo 3
    

    What this will do is to insert you specific variable (PAXPREFIX in this case) before the commands. If the variable is empty, it will not affect the command, as follows:

    pax> ./qq.sh
    my_porn.gz  copy_of_the_internet.gz
    00072
    3
    

    However, if it’s set to echo, it will prefix each line with that echo string.

    pax> PAXPREFIX=echo ./qq.sh
    ls /tmp
    printf %05d\n 72
    echo 3
    

    (a) The reason why it will only work for simple commands can be seen if you have something like:

    ${PAXPREFIX} ls -1 | tr '[a-z]' '[A-Z]'
    

    When PAXPREFIX is empty, it will simply give you the list of your filenames in uppercase. When it’s set to echo, it will result in:

    echo ls -1 | tr '[a-z]' '[A-Z]'
    

    giving:

    LS -1
    

    (not quite what you’d expect).

    In fact, you can see a problem with even the simple case above, where %05d\n is no longer surrounded by quotes.

    If you want a more robust solution, I’d opt for:

    if [[ ${PAXDEBUG:-0} -eq 1 ]] ; then
        echo /usr/bin/curl -c $PROXY --certkey $CERT --header ...
    else
             /usr/bin/curl -c $PROXY --certkey $CERT --header ...
    fi
    

    and use PAXDEBUG=1 myscript.sh to run it in debug mode. This is similar to what you have now but with the advantage that you don’t need to edit the file to switch between normal and debug modes.


    For debugging output from the shell itself, you can run it with bash -x or put set -x in your script to turn it on at a specific point (and, of course, turn it off with set +x).

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm looking for suggestions for debugging... If you view this site in Firefox or
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have some data like this: 1 2 3 4 5 9 2 6
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.