Arguments in C++ not received correctly from the Bash

Viewed 91

A debug version of my C++ code starts with:

int main(int argc,char* argv[])
{
        for(int i=0;i<argc;++i)
        {
                cout<<"argv["<<i<<"]="<<argv[i]<<endl;
        }
}

When a customer starts this software from the Bash using the command:

../Merge-2021-11-22_0906_NOVEMBER_DEV9-Ubuntu20.04_x86_64/merge --autoXML merge_combine_command_small_testcase/input.xml -o autoxml -M "-F 0.3 -I -o mergeout"

it prints:

argv[0]=/mnt/raid/1_Merge_Kernel_testing/combined_command_testing/Merge-2021-11-22_0906_NOVEMBER_DEV9-Ubuntu20.04_x86_64/bin/merge
argv[1]=--autoXML
argv[2]=merge_combine_command_small_testcase/input.xml
argv[3]=-o
argv[4]=autoxml
argv[5]=-M
argv[6]=-F
argv[7]=0.3
argv[8]=-I
argv[9]=-o
argv[10]=mergeout

...which is not correct because due to the double quotes argv[6] should be:

argv[6]=-F 0.3 -I -o mergeout

This is strange because it happens only on the customer's system while the Bash on my computer does it correctly. Initially I thought the problem is that his shell does not interpret the double quotes. But I wrote this script:

#!/bin/bash
echo param0: ${0}
echo param1: ${1}
echo param2: ${2}
echo param3: ${3}
echo param4: ${4}
echo param5: ${5}
echo param6: ${6}
echo param7: ${7}
echo param8: ${8}
echo param9: ${9}
echo param10: ${10}
echo param11: ${11}
echo param12: ${12}

and it prints the parameters correctly on his and on my system. Now I don't know how to debug this further. Any ideas what can cause the different behavior?

0 Answers
Related