2

Consider the following string:

./kmux.py  -r 'messenger.* xx'

If kmux.py is a python script, and the string above was given to bash as an argument, then sys.argv will be the following list:

["./kmux.py", "-r", "messenger.* xx"]

Is there a standard python function that will take the first string and turn it into the array?

I could manually replicate bash's logic in Python to take the original string and turn it into this array, but I am curious about whether such a function already exists.

merlin2011
  • 71,677
  • 44
  • 195
  • 329

1 Answers1

2

Use the default shlex package like so:

import shlex
shlex.split("'./kmux.py  -r 'messenger.* xx'")
hazrmard
  • 3,397
  • 4
  • 22
  • 36