How to know the parameter value in shlex.split

339 Views Asked by At

I have string variable as --test abc -a a -b b c, which is parameters for my linux script.

I am using python subprocess to execute this.

This string might be have special character like backtic or ', --test \"it's my test\" -a a -b b c in this case, I have to use pipes.quote to quote the value.

I can split this using shlex.split and get the paramters splited, I want to know that

In [21]: shlex.split("--test \"it's my test\" -a a -b b c")
Out[21]: ['--test', "it's my test", '-a', 'a', '-b', 'b', 'c']

From the list or shlex.split how can I check, which is value and which is the parameter?

I can check startswith('-') or startswith('--'), but is there any chance, it this logic might be wrong ?

0

There are 0 best solutions below