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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:22:05+00:00 2026-06-05T07:22:05+00:00

Let’s say I have shell programs a,b,c, each one executing a command from the

  • 0

Let’s say I have shell programs a,b,c, each one executing a command from the other one. For some reasons, I need quotes. Example:

a 'b 'c 'echo test'''

So a shall call b, which shall call c, which will call ‘echo test’. You already see that my quotes will be wrong interpreted. Also, note that a, b, and c are C-programs calling system().

Is there any solution to do that, preserving the quotes?

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

    I have no ready solution for C, but in this case, it is advisable to take your string-to-be-quoted, replace every ' with '\'' and enclose the whole stuff in '.

    1. The innermost part is echo test That can happily be put in '' and given to c: c 'echo test'.
    2. Then you want to give that string to b. Here it starts, because the said string contains 's, so you do ' + c '\''echo test'\'' + ' which you give to b: b 'c '\''echo test'\'''.
      What happens here? You have concatenated several concatenated parts for b‘s argument:

      1. 'c ', which becomes justc `,
      2. \', which becomes '
      3. 'echo test', which is echo test after stripping the quotes,
      4. \' again -> ', and
      5. '' which is nothing and only exists because there is a ' at the end of the original string. It can be omitted if processed manually, but isn’t worth the effort in an algorithm.

      So you get c 'echo test' after dequoting that, which shows that the said algorithm should work.

    3. Now you do this process to b 'c '\''echo test'\''' again in order to have an argument for a: so you’ll get a 'b '\''c '\''\'\'''\''echo test'\''\'\'''\'''\'''.

    4. Even trickier: you now want to put that in a C string, so you’ll have to double the \s: system("a 'b '\\''c '\\''\\'\\'''\\''echo test'\\''\\'\\'''\\'''\\'''");.

    If you do the said optimization on starting, ending and successive 's, you get

    b 'c '\''echo test'\'
    

    and

    a 'b '\''c '\''\'\'\''echo test'\''\'\'
    

    resp.

    system("a 'b '\\''c '\\''\\'\\'\\''echo test'\\''\\'\\'");
    

    .

    Alternatively, you could work without the ' and just quote the spaces and the ‘\’s, but that would probably even trickier…

    Let me try:

    1. c: echo test -> echo\ test -> c echo\ test.
    2. b: b c\ echo\\\ test.
    3. a: a b\ c\\\ echo\\\\\\\ test.
    4. system: system("a b\\ c\\\\\\ echo\\\\\\\\\\\\\\ test").

    Quote ugly, but it works.

    Tested with

    #!/usr/bin/env python
    import sys
    
    import subprocess
    sp=subprocess.Popen(sys.argv[1], shell=True, stdout=subprocess.PIPE)
    for line in sp.stdout:
        print "%s> %s" % (sys.argv[0], line),
    exit(sp.wait())
    

    as a, b and c and

    import os
    print 1
    os.system("a 'b '\\''c '\\''\\'\\'''\\''echo test'\\''\\'\\'''\\'''\\'''")
    print 2
    os.system("a 'b '\\''c '\\''\\'\\'\\''echo test'\\''\\'\\'")
    print 3
    os.system("a b\\ c\\\\\\ echo\\\\\\\\\\\\\\ test")
    

    as test.py and called with

    PATH=.:$PATH python -m test
    

    As python has in this case the same quoting rules as C, it is a sufficient test.

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

Sidebar

Related Questions

Let's say we have 3 classes: A, B and C. Each class has the
Let's say I have a C++ Visual Studio 2010 solution with 2 projects: one
Let's say I have one class User, and it has a property of type
Let's say I have the string: hello world; some random text; foo; How could
Let say I have some code HTML code: <ul> <li> <h1>Title 1</h1> <p>Text 1</p>
Let's say I have a javascript array with a bunch of elements (anywhere from
Let's say I have some json like this in mongo: {n:5} and a java
Let's say I want to have some kind of a cache that did something
let's say I have a select list as follows: <select name='languages'> <option value='german'>German</option> <option
Let's say I have the following classes : public class MyProductCode { private String

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.