Find the answer to your Linux question:
Results 1 to 3 of 3
Hi all, I wrote a C++ program that uses two different parsers. The first parser is reading program arguments from command line: ./mybin arg1 arg2 ... then during program execution ...
  1. #1
    Just Joined!
    Join Date
    Jan 2011
    Posts
    2

    Bash script : pass arguments to second level parser

    Hi all,

    I wrote a C++ program that uses two different parsers. The first parser is reading program arguments from command line:

    ./mybin arg1 arg2 ...

    then during program execution there's an interactive prompt asking for more parameters:

    ...
    >> (second bunch of arguments here)
    ...

    I'd like to run my program inside a bash script, but I don't know how to give the second level arguments. Any help on how to do that?

    thanks in advance.

    drugo

  2. #2
    Just Joined!
    Join Date
    Jan 2010
    Posts
    27
    I would go following way:

    Code:
    #!/bin/bash
    
    MYARGS_1="vienas du trys"
    MYARGS_2="uno dos tres"
    
    echo $MYARGS_2 | ./main.exe $MYARGS_1
    Would you need an argument containing spaces, it should be enhanced a bit.

  3. #3
    Just Joined!
    Join Date
    Jan 2011
    Posts
    2
    thanks saulius2, I managed to pass the args using bash "here documents". something like

    Code:
    #!/bin/bash
    
    ARGS_L1="par1 par2"
    ARGS_L2="par3"
    
    ./mybin $ARGS_L1 << EOF
    $ARGS_L2
    EOF
    
    exit 0
    both solutions work.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...