0

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 ?

Nilesh
  • 20,521
  • 16
  • 92
  • 148
  • Yes: it is entirely up to the program receiving the arguments to interpret some of them as options. For instance, `-test` could be a single option named `test`, or it could be interpreted as a shortcut for `-t -e -s -t`. It might use some character other than `-` to indicate an option; `argparse` itself supports this. Why do you need to identify options? – chepner May 18 '17 at 18:24
  • Thanks Chepner, If I am using `shell script` then my approch is right ? – Nilesh May 18 '17 at 18:35
  • @chepner as i mentioned, I need to apply `pipe.quote` so it will not break the process with special character. – Nilesh May 18 '17 at 18:36

0 Answers0