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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:26:54+00:00 2026-06-05T11:26:54+00:00

Problem I would like to use the parameters given to a script as is

  • 0

Problem

I would like to use the parameters given to a script as is – with quotes and everything. So far, all solutions I found strip the quotes, or do something subtly different.

Scenario

I have a tool that accepts strings as command line parameters, for instance

./tool --formula="AG EF phi;"

I further have a wrapper script that should call the script. Its invocation should be

wrap.sh ./tool --formula="AG EF phi;"

This script does something like

# preparation phase
# ...

# call tool and remember exit code
$*
result=$?

# evaluation phase
# ...

exit $result

Unfortunately, the tool is then called as

./tool --formula=AG EF phi;

which is not the same as above and would yield a syntax error. The only hacks I found would give me something like

./tool "--formula=AG EF phi;"

which is also wrong.

Details

To be concrete, here is some dummy code to exemplify the problem:

First, the C program “tool.c”.

#include <stdio.h>

int main(int argc, char** argv) {
    int i;
    for (i = 0; i < argc; i++) {
        printf("%d: %s\n", i, argv[i]);
    }
    return 0;
}

Then, the wrap script “wrap.sh”:

#!/bin/bash
echo $*
$*
exit $?

Now here is what I tried:

$ ./tool --formula="Foo bar"
0: ./tool
1: --formula=Foo bar

$ ./wrap.sh ./tool --formula="Foo bar"
./tool --formula=Foo bar
0: ./tool
1: --formula=Foo
2: bar

$ ./wrap.sh ./tool --formula="\"Foo bar\""
./tool --formula="Foo bar"
0: ./tool
1: --formula="Foo
2: bar"

$ ./wrap.sh ./tool --formula="\"Foo bar\""
./tool --formula="Foo bar"
0: ./tool
1: --formula="Foo
2: bar"

$ ./wrap.sh "./tool --formula=\"\\\"Foo bar\\\"\""
./tool --formula="\"Foo bar\""
0: ./tool
1: --formula="\"Foo
2: bar\""

And here is what I want (for whatever necessary change in the wrap script):

$ ./wrap.sh ./tool --formula="Foo bar"
0: ./tool
1: --formula=Foo bar

Proposals

Escape Quotes

When I escape quotes like Shabaz proposed, the variable $* contains correctly quoted strings, for instance:

wrap.sh ./tool --formula="\"AG EF phi;\""

and then in wrap.sh the code:

echo $*

would produce

./tool --formula="AG EF phi;"

However, executing $* produces the exact error as above: The argument of formula is stripped after “AG”. Furthermore, it would be nice not to escape quotes.

Could a different shell help?

  • 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-06-05T11:26:56+00:00Added an answer on June 5, 2026 at 11:26 am

    You can use this script that works to preserve the white-spaces you want:

    #!/bin/bash
    exec bash -c "$*"
    ret=$?
    exit $ret
    

    Execute above script using this command line:

    ./wrap.sh ./tool --formula="\"Foo bar baz\""
    

    OUTPUT:

    0: ./tool
    1: --formula=Foo bar baz
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm stumped by this seemingly trivial problem... I would like to use python to
I would like to use NSOperations in my application to resolve threading problems. I
Problem: I would like to share code between multiple assemblies. This shared code will
I have a problem i would like parallelize two for loops with openmp. how
i have the following problem: i would like to create a footer. that footer
I have a reasonably complex layout problem: I would like to have a main
Ok, I have the following problem: I would like to scroll an overflowing ListBox
while designing my user control, i encountered the following problem: i would like to
I have a little problem where I would like to insert a svn diff
I have an interesting genetics problem that I would like to solve in native

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.